octo-deno/lib/make/time.ts

42 lines
936 B
TypeScript
Raw Permalink Normal View History

2020-02-04 12:49:42 +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/. */
import random from "../random/random.ts";
import numbers from "./numbers.ts";
export default class time {
static unit() {
return random.pick(["s", "ms"]);
}
static datetime() {
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() {
return time.datetime().toDateString();
}
static time() {
return time.datetime().toTimeString();
}
static iso() {
return time.datetime().toISOString();
}
static epoch() {
return Math.floor(time.datetime().getTime() / 1000);
}
static any() {
return numbers.any() + time.unit();
}
}