Skip to content

Commit

Permalink
fix: resolve the problem that time of primitive type can't store in s…
Browse files Browse the repository at this point in the history
…chema
  • Loading branch information
Chinlinlee committed Oct 26, 2021
1 parent d7eabc3 commit 672fb63
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions models/mongodb/FHIRDataTypesSchema/time.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
const moment = require('moment');
module.exports = {
type: Date,
type: Number,
default: void 0,
set: function(v) {
let timeDate = moment(v, "hh:mm:ss.SSS").toDate();
let storeTime = timeDate.getHours() * 3600000 + timeDate.getMinutes() * 60000+ timeDate.getSeconds() * 1000 + timeDate.getMilliseconds();
console.log(storeTime);
return storeTime;
},
get: function(v) {
return moment(v).format('hh:mm:ss');
let hours = parseInt(v / 3600000);
let leaves = v - hours * 3600000;
let minutes = parseInt(leaves / 60000);
let leavesSeconds = (leaves - minutes * 60000);
let seconds = parseInt(leavesSeconds / 1000);
let milliSeconde = leavesSeconds - seconds * 1000;
if (milliSeconde > 0 ) {
return `${hours.toString().padStart(2,"00")}:${minutes.toString().padStart(2,"00")}:${seconds.toString().padStart(2,"00")}.${milliSeconde.toString().padStart(3,"000")}`;
}
return `${hours.toString().padStart(2,"00")}:${minutes.toString().padStart(2,"00")}:${seconds.toString().padStart(2,"00")}`;
}
}

0 comments on commit 672fb63

Please sign in to comment.