typescript-dotnet-amd
Version:
A JavaScript-Friendly .NET Based TypeScript Library.
7 lines • 5.26 kB
JavaScript
/*!
* @author electricessence / https://github.com/electricessence/
* Based on .NET DateTime's interface.
* Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
*/
define(["require","exports","./TimeSpan","./ClockTime","./TimeStamp","../Exceptions/ArgumentNullException"],function(e,t,n,i,r,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var a=void 0,u=function(){function e(t,n){void 0===t&&(t=new Date),void 0===n&&(n=e.Kind.Local),this._kind=n,t instanceof e?(this._value=t.toJsDate(),n===a&&(this._kind=t._kind)):t instanceof Date?this._value=new Date(t.getTime()):this._value=t===a?new Date:new Date(t)}return e.prototype.toJsDate=function(){return new Date(this._value.getTime())},Object.defineProperty(e.prototype,"kind",{get:function(){return this._kind},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"year",{get:function(){return this._value.getFullYear()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"month",{get:function(){return this._value.getMonth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"calendarMonth",{get:function(){return this._value.getMonth()+1},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"calendar",{get:function(){return{year:this.year,month:this.calendarMonth,day:this.day}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"day",{get:function(){return this._value.getDate()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dayIndex",{get:function(){return this._value.getDate()-1},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dayOfWeek",{get:function(){return this._value.getDay()},enumerable:!0,configurable:!0}),e.prototype.addMilliseconds=function(t){return t=t||0,new e(this._value.getTime()+t,this._kind)},e.prototype.addSeconds=function(e){return e=e||0,this.addMilliseconds(1e3*e)},e.prototype.addMinutes=function(e){return e=e||0,this.addMilliseconds(6e4*e)},e.prototype.addHours=function(e){return e=e||0,this.addMilliseconds(36e5*e)},e.prototype.addDays=function(e){return e=e||0,this.addMilliseconds(864e5*e)},e.prototype.addMonths=function(t){t=t||0;var n=this.toJsDate();return n.setMonth(n.getMonth()+t),new e(n,this._kind)},e.prototype.addYears=function(t){t=t||0;var n=this.toJsDate();return n.setFullYear(n.getFullYear()+t),new e(n,this._kind)},e.prototype.add=function(e){return this.addMilliseconds(e.getTotalMilliseconds())},e.prototype.subtract=function(e){return this.addMilliseconds(-e.getTotalMilliseconds())},e.prototype.timePassedSince=function(t){return e.between(t,this)},Object.defineProperty(e.prototype,"date",{get:function(){var t=this;return new e(new Date(t.year,t.month,t.day),t._kind)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"timeOfDay",{get:function(){var e=this,t=e._time;if(!t){var n=this._value;e._time=t=new i.ClockTime(n.getHours(),n.getMinutes(),n.getSeconds(),n.getMilliseconds())}return t},enumerable:!0,configurable:!0}),e.prototype.toTimeStamp=function(){return r.TimeStamp.from(this)},Object.defineProperty(e,"now",{get:function(){return new e},enumerable:!0,configurable:!0}),e.prototype.toUniversalTime=function(){var t=this;if(t._kind!=e.Kind.Local)return new e(t,t._kind);var n=t._value;return new e(new Date(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds()),e.Kind.Utc)},e.prototype.equals=function(t,n){if(void 0===n&&(n=!1),!t)return!1;if(t==this)return!0;if(t instanceof Date){var i=this._value;return t==i||t.getTime()==i.getTime()}if(t instanceof e){if(n){var r=t._kind;if(!r&&this._kind||r!=this._kind)return!1}return this.equals(t._value)}return!n&&this.equals(t.toJsDate())},e.prototype.compareTo=function(t){if(!t)throw new o.ArgumentNullException("other");if(t==this)return 0;t instanceof e&&(t=t._value);var n=this._value.getTime();return t instanceof Date?n-t.getTime():n-t.toJsDate().getTime()},e.prototype.equivalent=function(t){if(!t)return!1;if(t==this)return!0;if(t instanceof Date){var n=this._value;return n.toUTCString()==t.toUTCString()}return!!(t instanceof e&&this.equals(t,!0))||this.equivalent(t.toJsDate())},Object.defineProperty(e,"today",{get:function(){return e.now.date},enumerable:!0,configurable:!0}),Object.defineProperty(e,"tomorrow",{get:function(){var t=e.today;return t.addDays(1)},enumerable:!0,configurable:!0}),e.between=function(t,i){var r=t instanceof e?t._value:t,o=i instanceof e?i._value:i;return new n.TimeSpan(o.getTime()-r.getTime())},e.isLeapYear=function(e){return e%4==0&&e%100!=0||e%400==0},e.daysInMonth=function(e,t){return new Date(e,t+1,0).getDate()},e.from=function(t,n,i){void 0===n&&(n=0),void 0===i&&(i=1);var r;return"object"==typeof t?(i=t.day,n=t.month,r=t.year):r=t,new e(new Date(r,n,i))},e.fromCalendarDate=function(t,n,i){void 0===n&&(n=1),void 0===i&&(i=1);var r;return"object"==typeof t?(i=t.day,n=t.month,r=t.year):r=t,new e(new Date(r,n-1,i))},e}();t.DateTime=u,function(e){var t;!function(e){e[e.Unspecified=0]="Unspecified",e[e.Local=1]="Local",e[e.Utc=2]="Utc"}(t=e.Kind||(e.Kind={}))}(u=t.DateTime||(t.DateTime={})),t.DateTime=u,Object.freeze(u),t["default"]=u});
//# sourceMappingURL=DateTime.js.map