octo-deno/lib/make/datetime.js

36 lines
812 B
JavaScript
Raw Normal View History

2017-06-26 18:43:25 +00:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const make = require('../make')
const random = require('../random')
class datetime extends make {
static object () {
2017-06-26 18:43:25 +00:00
switch (random.number(2)) {
case 0:
return new Date(new Date().getTime() + random.number())
case 1:
return new Date(new Date().getTime() - random.number())
}
}
static date () {
2017-09-13 02:13:50 +00:00
return this.object().toDateString()
}
static time () {
2017-09-13 02:13:50 +00:00
return this.object().toTimeString()
}
static iso () {
2017-09-13 02:13:50 +00:00
return this.object().toISOString()
}
static epoch () {
2017-11-27 16:53:48 +00:00
return Math.floor(this.object() / 1000)
2017-06-26 18:43:25 +00:00
}
}
module.exports = datetime