UNPKG

@ncodedcode/ncode_react_lib

Version:

ncode react application context library

211 lines 7.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NCDate = exports.getNCDateToString = exports.NCDateUnit = void 0; var NCDating_1 = require("./NCDating"); var Inject_1 = require("../../di/Inject"); var NCDateUnit; (function (NCDateUnit) { NCDateUnit["millisecond"] = "millisecond"; NCDateUnit["second"] = "second"; NCDateUnit["minute"] = "minute"; NCDateUnit["hour"] = "hour"; NCDateUnit["day"] = "day"; NCDateUnit["month"] = "month"; NCDateUnit["year"] = "year"; NCDateUnit["date"] = "date"; NCDateUnit["milliseconds"] = "milliseconds"; NCDateUnit["seconds"] = "seconds"; NCDateUnit["minutes"] = "minutes"; })(NCDateUnit = exports.NCDateUnit || (exports.NCDateUnit = {})); var getNCDateToString = function (date, format) { if (format === void 0) { format = NCDate.FORMAT_LOCAL_DATE_COMMA; } return date ? date.toString(format) : ""; }; exports.getNCDateToString = getNCDateToString; var NCDate = (function () { function NCDate(dating) { var _this = this; this.toCommaYYMMDD = function () { return _this.dating.format(NCDate.FORMAT_LOCAL_DATE_COMMA).slice(2); }; this.year = function () { return _this.dating.year(); }; this.month = function () { return _this.dating.month(); }; this.day = function () { return _this.dating.day(); }; this.hour = function () { return _this.dating.hour(); }; this.minute = function () { return _this.dating.minute(); }; this.second = function () { return _this.dating.second(); }; this.monthName = function () { var months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ]; return months[_this.month() - 1]; }; this.monthNameShort = function () { var months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; return months[_this.month() - 1]; }; this.monthNameKo = function () { var months = [ "1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월", ]; return months[_this.month() - 1]; }; this.isAm = function () { return _this.hour() < 12; }; this.isPm = function () { return !_this.isAm(); }; this.weekDay = function () { return _this.dating.dayOfWeek(); }; this.weekDayName = function () { var weekdays = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", ]; return weekdays[_this.dating.dayOfWeek()]; }; this.weekDayNameShort = function () { var weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; return weekdays[_this.dating.dayOfWeek()]; }; this.weekDayNameKo = function () { var weekdays = [ "일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일", ]; return weekdays[_this.dating.dayOfWeek()]; }; this.weekDayNameKoShort = function () { var weekdays = ["일", "월", "화", "수", "목", "금", "토"]; return weekdays[_this.dating.dayOfWeek()]; }; this.convertDateToText = function () { return "".concat(_this.dating.year(), ".").concat(_this.dating.month(), ".").concat(_this.dating.day(), " ").concat(_this.dating.hour() <= 12 ? "".concat(_this.dating.hour(), "AM") : "".concat(_this.dating.hour() - 12, "PM")); }; this.convertDateToTextWithoutTime = function () { return "".concat(_this.dating.year(), ".").concat(_this.dating.month(), ".").concat(_this.dating.day()); }; this.isPast = function () { return _this.dating.isPast(); }; this.isFuture = function () { return _this.dating.isFuture(); }; this.isClosing = function () { var target = NCDate.fromDate(_this.dating.toDate()).addDay(-2); return NCDate.now().isLaterThen(target); }; this.isEarlierThen = function (target) { return _this.dating.compare(target.dating) < 0; }; this.isLaterThen = function (target) { return _this.dating.compare(target.dating) > 0; }; this.equals = function (target) { var myMilli = _this.toMilliseconds(); var targetMilli = 0; if (target instanceof NCDate) { targetMilli = target.toMilliseconds(); } else if (target instanceof Date) { targetMilli = target.getTime(); } else { targetMilli = target; } return Math.floor(myMilli / 1000) === Math.floor(targetMilli / 1000); }; this.dateEquals = function (target) { var myDate = _this.toString(NCDate.FORMAT_LOCAL_DATE); var targetDate = target.toString(NCDate.FORMAT_LOCAL_DATE); return myDate === targetDate; }; this.addDay = function (day) { return new NCDate(_this.dating.addDayTo(day)); }; this.dating = dating; } NCDate.now = function () { return new NCDate(NCDate.resolveDating().now()); }; NCDate.create = function (milliseconds) { return new NCDate(NCDate.resolveDating().create(milliseconds)); }; NCDate.duration = function (milliseconds, format, unit) { return NCDate.resolveDating().duration(milliseconds, format, unit); }; NCDate.fromDate = function (date) { return new NCDate(NCDate.resolveDating().fromDate(date)); }; NCDate.parse = function (dateString) { return new NCDate(NCDate.resolveDating().parse(dateString)); }; NCDate.prototype.toString = function (format) { if (format === void 0) { format = NCDate.FORMAT_UTC_ISO; } if (format === NCDate.FORMAT_UTC_ISO) return this.dating.isoFormat(); return this.dating.format(format); }; NCDate.prototype.toMilliseconds = function () { return this.dating.millis(); }; NCDate.prototype.toDate = function () { return this.dating.toDate(); }; NCDate.prototype.diff = function (date, unit, float) { if (float === void 0) { float = false; } var _date = date.toDate(); return this.dating.diff(_date, unit, float); }; NCDate.FORMAT_UTC_ISO = "NCDATE_FORMAT_UTC_ISO"; NCDate.FORMAT_LOCAL_DATETIME = "YYYY-MM-DD HH:mm:ss"; NCDate.FORMAT_LOCAL_DATETIME_COMMA = "YYYY.MM.DD HH:mm"; NCDate.FORMAT_LOCAL_DATE = "YYYY-MM-DD"; NCDate.FORMAT_LOCAL_DATE_COMMA = "YYYY.MM.DD"; NCDate.FORMAT_LOCAL_MONTH_DAY_WEEK_COMMA = "MM.DD ddd"; NCDate.FORMAT_MONTH_DATE_YEAR = "MMM D, YYYY"; NCDate.FORMAT_MONTH_DATE = "M월 D일"; NCDate.resolveDating = function () { return (0, Inject_1.Inject)(NCDating_1.NCDatingClassName); }; return NCDate; }()); exports.NCDate = NCDate; //# sourceMappingURL=NCDate.js.map