Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/mock/random/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,18 @@ module.exports = {
_randomDate: function(min, max) { // min, max
min = min === undefined ? new Date(0) : min
max = max === undefined ? new Date() : max
return new Date(Math.random() * (max.getTime() - min.getTime()))
return new Date(Math.random() * (max.getTime() - min.getTime()) + min.getTime())
},
// 返回一个随机的日期字符串。
date: function(format) {
format = format || 'yyyy-MM-dd'
return this._formatDate(this._randomDate(), format)
},
// 返回一个区间内随机的日期字符串。
dateRange: function(min,max,format) {
format = format || 'yyyy-MM-dd'
return this._formatDate(this._randomDate(new Date(min),new Date(max)), format)
},
// 返回一个随机的时间字符串。
time: function(format) {
format = format || 'HH:mm:ss'
Expand Down Expand Up @@ -138,4 +143,4 @@ module.exports = {

return this._formatDate(date, format)
}
}
}