-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve the problem that time of primitive type can't store in s…
…chema
- Loading branch information
1 parent
d7eabc3
commit 672fb63
Showing
1 changed file
with
17 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")}`; | ||
} | ||
} |