UNPKG

@tsdotnet/date-time

Version:

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/tsdotnet/date-time/blob/master/LICENSE) ![npm-publish](https://github.com/tsdotnet/date-time/workflows/npm-publish/badge.svg) [![npm version](htt

42 lines 1.4 kB
"use strict"; /*! * @author electricessence / https://github.com/electricessence/ * @license MIT */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeStamp = void 0; const tslib_1 = require("tslib"); const type_1 = tslib_1.__importDefault(require("@tsdotnet/type")); class TimeStamp { constructor(year, month, day = 1, hour = 0, minute = 0, second = 0, millisecond = 0, tick = 0) { this.year = year; this.month = month; this.day = day; this.hour = hour; this.minute = minute; this.second = second; this.millisecond = millisecond; this.tick = tick; Object.freeze(this); } static from(d) { if (!(d instanceof Date) && type_1.default.hasMember(d, 'toJsDate')) d = d.toJsDate(); if (d instanceof Date) { return new TimeStamp(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()); } else { throw Error('Invalid date type.'); } } static now() { return TimeStamp.from(new Date()); } toJsDate() { const _ = this; return new Date(_.year, _.month, _.day, _.hour, _.minute, _.second, _.millisecond + _.tick / 10000); } } exports.TimeStamp = TimeStamp; exports.default = TimeStamp; //# sourceMappingURL=TimeStamp.js.map