UNPKG

metro4

Version:

The front-end framework for Build responsive, mobile-first projects on the web with the first front-end component library in Metro Style

1,613 lines (1,331 loc) 1.34 MB
/* * Metro 4 Components Library v4.5.0 (https://metroui.org.ua) * Copyright 2012-2021 Sergey Pimenov * Built at 01/08/2021 18:53:43 * Licensed under MIT */ /*! * Datetime v1.0.0, (https://github.com/olton/DatetimeJS.git) * Copyright 2021 by Serhii Pimenov (https://pimenov.com.ua) * Datetime.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with comfortable modern API. * Build at 11/01/2021 21:09:55 * Licensed under MIT !*/ (function(global) { 'use strict'; var DEFAULT_FORMAT = "YYYY-MM-DDTHH:mm:ss.sss"; var INVALID_DATE = "Invalid date"; var REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|m{1,2}|s{1,3}/g; global['DATETIME_LOCALES'] = { "en": { months: "January February March April May June July August September October November December".split(" "), monthsShort: "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "), weekdays: "Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "), weekdaysShort: "Sun Mon Tue Wed Thu Fri Sat".split(" "), weekdaysMin: "Su Mo Tu We Th Fr Sa".split(" "), weekStart: 0 } } var M = { ms: "Milliseconds", s: "Seconds", m: "Minutes", h: "Hours", D: "Date", d: "Day", M: "Month", Y: "FullYear", y: "Year", t: "Time" } var C = { ms: "ms", s: "second", m: "minute", h: "hour", D: "day", W: "week", d: "weekDay", M: "month", Y: "year", Y2: "year2", t: "time", c: "century", q: "quarter" } var lpad = function(str, pad, length){ var _str = ""+str; if (length && _str.length >= length) { return _str; } return Array((length + 1) - _str.length).join(pad) + _str; } var not = function(v){ return typeof v === "undefined" || v === null; } var datetime = function(){ var args; if (arguments[0] instanceof Datetime) { return datetime(arguments[0].value); } args = [].slice.call(Array.isArray(arguments[0]) ? arguments[0] : arguments); return new (Function.prototype.bind.apply(Datetime, [this].concat(args) ) ); } var Datetime = function(){ var args = [].slice.call(arguments); this.value = new (Function.prototype.bind.apply(Date, [this].concat(args) ) ); this.locale = "en"; this.weekStart = global['DATETIME_LOCALES']["en"].weekStart; this.utcMode = false; this.mutable = true; if (isNaN(this.value.getTime())) { throw new Error(INVALID_DATE); } } Datetime.DEFAULT_FORMAT = DEFAULT_FORMAT; Datetime.REGEX_FORMAT = REGEX_FORMAT; Datetime.INVALID_DATE = INVALID_DATE; Datetime.lpad = lpad; Datetime.not = not; Datetime.isDatetime = function(val){ return val instanceof Datetime; } Datetime.now = function(asDate){ return datetime()[asDate ? "val" : "time"](); } Datetime.locale = function(name, locale){ global['DATETIME_LOCALES'][name] = locale; } Datetime.getLocale = function(locale){ return global['DATETIME_LOCALES'][locale || "en"] || global['DATETIME_LOCALES']["en"]; } Datetime.parse = function(str){ return datetime(Date.parse(str)); } Datetime.align = function(d, align){ var date = d instanceof Datetime ? d : datetime(d), result, temp; switch (align) { case C.s: result = date.ms(0); break; //second case C.m: result = Datetime.align(date, C.s)[C.s](0); break; //minute case C.h: result = Datetime.align(date, C.m)[C.m](0); break; //hour case C.D: result = Datetime.align(date, C.h)[C.h](0); break; //day case C.M: result = Datetime.align(date, C.D)[C.D](1); break; //month case C.Y: result = Datetime.align(date, C.M)[C.M](0); break; //year case C.W: { temp = date.weekDay(); result = Datetime.align(date, C.D).addDay(-temp); break; // week } default: result = date; } return result; } Datetime.alignEnd = function(d, align){ var date = d instanceof Datetime ? d : datetime(d), result, temp; switch (align) { case C.ms: result = date.ms(999); break; //second case C.s: result = Datetime.alignEnd(date, C.ms); break; //second case C.m: result = Datetime.alignEnd(date, C.s)[C.s](59); break; //minute case C.h: result = Datetime.alignEnd(date, C.m)[C.m](59); break; //hour case C.D: result = Datetime.alignEnd(date, C.h)[C.h](23); break; //day case C.M: result = Datetime.alignEnd(date, C.D)[C.D](1).add(1, C.M).add(-1, C.D); break; //month case C.Y: result = Datetime.alignEnd(date, C.D)[C.M](11)[C.D](31); break; //year case C.W: { temp = date.weekDay(); result = Datetime.alignEnd(date, 'day').addDay(6 - temp); break; // week } default: result = date; } return result; } Datetime.extend = function(where){ var options, name, length = arguments.length; for (var i = 1; i < length; i++ ) { if ( ( options = arguments[ i ] ) != null ) { for ( name in options ) { if (Object.prototype.hasOwnProperty.call(options, name)) where[ name ] = options[ name ]; } } } return where; }; Datetime.use = function(obj){ Datetime.extend(Datetime.prototype, obj); } Datetime.useStatic = function(obj){ Datetime.extend(Datetime, obj); } Datetime.prototype = { immutable: function(v){ this.mutable = !(not(v) ? true : v); return this; }, utc: function(){ this.utcMode = true; return this; }, local: function(){ this.utcMode = false return this; }, useLocale: function(val){ if (!Datetime.getLocale(val)) { console.warn("Locale " + val + " is not defined!"); return this; } this.locale = val; this.weekStart = Datetime.getLocale(val).weekStart; return this; }, clone: function(){ var c = datetime(this.value); c.locale = this.locale; c.weekStart = this.weekStart; c.mutable = this.mutable; return c; }, align: function(to){ if (this.mutable) { this.value = Datetime.align(this, to).val(); return this; } return this.clone().immutable(false).align(to).immutable(!this.mutable); }, alignEnd: function(to){ if (this.mutable) { this.value = Datetime.alignEnd(this, to).val(); return this; } return this.clone().immutable(false).alignEnd(to).immutable(!this.mutable); }, val: function(val){ if ( !(val instanceof Date) ) return this.value; if (this.mutable) { this.value = val; return this; } return datetime(val); }, year2: function(){ return +(""+this.year()).substr(-2); }, _set: function(m, v){ var fn = "set" + (this.utcMode && m !== "t" ? "UTC" : "") + M[m]; if (this.mutable) { this.value[fn](v); return this; } var clone = this.clone(); clone.value[fn](v); return clone; }, _get: function(m){ var fn = "get" + (this.utcMode && m !== "t" ? "UTC" : "") + M[m]; return this.value[fn](); }, _work: function(part, val){ if (!arguments.length || (typeof val === "undefined" || val === null)) { return this._get(part); } return this._set(part, val); }, ms: function(val){ return this._work("ms", val);}, second: function(val){return this._work("s", val);}, minute: function(val){return this._work("m", val); }, hour: function(val){return this._work("h", val);}, day: function(val){return this._work("D", val);}, month: function(val){return this._work("M", val);}, year: function(val){return this._work("Y", val);}, time: function(val){return this._work("t", val);}, weekDay: function(val){ if (!arguments.length || (not(val))) { return this.utcMode ? this.value.getUTCDay() : this.value.getDay(); } var curr = this.weekDay(); var diff = val - curr; this.day(this.day() + diff); return this; }, get: function(unit){ return typeof this[unit] !== "function" ? this : this[unit](); }, set: function(unit, val){ return typeof this[unit] !== "function" ? this : this[unit](val); }, add: function(val, to){ switch (to) { case C.h: return this.time(this.time() + (val * 60 * 60 * 1000)); case C.m: return this.time(this.time() + (val * 60 * 1000)); case C.s: return this.time(this.time() + (val * 1000)); case C.ms: return this.time(this.time() + (val)); case C.D: return this.day(this.day() + val); case C.W: return this.day(this.day() + val * 7); case C.M: return this.month(this.month() + val); case C.Y: return this.year(this.year() + val); } }, addHour: function(v){return this.add(v,C.h);}, addMinute: function(v){return this.add(v,C.m);}, addSecond: function(v){return this.add(v, C.s);}, addMs: function(v){return this.add(v, C.ms);}, addDay: function(v){return this.add(v,C.D);}, addWeek: function(v){return this.add(v,C.W);}, addMonth: function(v){return this.add(v, C.M);}, addYear: function(v){return this.add(v, C.Y);}, format: function(fmt, locale){ var format = fmt || DEFAULT_FORMAT; var names = Datetime.getLocale(locale || this.locale); var year = this.year(), year2 = this.year2(), month = this.month(), day = this.day(), weekDay = this.weekDay(); var hour = this.hour(), minute = this.minute(), second = this.second(), ms = this.ms(); var matches = { YY: year2, YYYY: year, M: month + 1, MM: lpad(month + 1, "0", 2), MMM: names.monthsShort[month], MMMM: names.months[month], D: day, DD: lpad(day, "0", 2), d: weekDay, dd: names.weekdaysMin[weekDay], ddd: names.weekdaysShort[weekDay], dddd: names.weekdays[weekDay], H: hour, HH: lpad(hour, "0", 2), m: minute, mm: lpad(minute,"0", 2), s: second, ss: lpad(second,"0", 2), sss: lpad(ms,"0", 3) }; return format.replace(REGEX_FORMAT, function(match, $1){ return $1 || matches[match]; }); }, valueOf: function(){ return this.value.valueOf(); }, toString: function(){ return this.value.toString(); } } global.Datetime = Datetime; global.datetime = datetime; }(typeof self === "undefined" ? typeof global === "undefined" ? window : global : self)); (function() { 'use strict'; var fnFormat = Datetime.prototype.format; Datetime.use({ buddhist: function(){ return this.year() + 543; }, format: function(format, locale){ format = format || Datetime.DEFAULT_FORMAT; var matches = { BB: (this.buddhist()+"").slice(-2), BBBB: this.buddhist() } var result = format.replace(/(\[[^\]]+])|B{4}|B{2}/g, function(match, $1){ return $1 || matches[match]; }) return fnFormat.bind(this)(result, locale) } }); }()); (function() { 'use strict'; Datetime.use({ calendar: function(iso){ return Datetime.calendar(this, iso); } }); Datetime.useStatic({ calendar: function(d, iso){ var date = d instanceof Datetime ? d.clone().align("month") : datetime(d); var ws = iso === 0 || iso ? iso : date.weekStart; var wd = ws ? date.isoWeekDay() : date.weekDay(); var names = Datetime.getLocale(date.locale); var now = datetime(), i; var getWeekDays = function (wd, ws){ if (ws === 0) { return wd; } var su = wd[0]; return wd.slice(1).concat([su]); } var result = { month: names.months[date.month()], days: [], weekstart: iso ? 1 : 0, weekdays: getWeekDays(names.weekdaysMin,ws), today: now.format("YYYY-MM-DD"), weekends: [], week: [] }; date.addDay(ws ? -wd+1 : -wd); for(i = 0; i < 42; i++) { result.days.push(date.format("YYYY-MM-DD")); date.add(1, 'day'); } result.weekends = result.days.filter(function(v, i){ var def = [0,6,7,13,14,20,21,27,28,34,35,41]; var iso = [5,6,12,13,19,20,26,27,33,34,40,41]; return ws === 0 ? def.indexOf(i) > -1 : iso.indexOf(i) > -1; }); date = now.clone(); wd = ws ? date.isoWeekDay() : date.weekDay(); date.addDay(ws ? -wd+1 : -wd); for (i = 0; i < 7; i++) { result.week.push(date.format("YYYY-MM-DD")); date.add(1, 'day'); } return result; } }); }()); (function() { 'use strict'; var oldFormat = Datetime.prototype.format; Datetime.use({ century: function(){ return parseInt(this.year() / 100); }, format: function(format, locale){ format = format || Datetime.DEFAULT_FORMAT; var matches = { C: this.century() } var result = format.replace(/(\[[^\]]+])|C/g, function(match, $1){ return $1 || matches[match]; }) return oldFormat.bind(this)(result, locale) } }) }()); (function() { 'use strict'; Datetime.use({ same: function(d){ return this.time() === datetime(d).time(); }, compare: function(d, align, operator){ var date = datetime(d); var curr = datetime(this.value); var t1, t2; operator = operator || "="; if (["<", ">", ">=", "<=", "=", "!="].indexOf(operator) === -1) { operator = "="; } align = (align || "ms").toLowerCase(); t1 = curr.align(align).time(); t2 = date.align(align).time(); switch (operator) { case "<": return t1 < t2; case ">": return t1 > t2; case "<=": return t1 <= t2; case ">=": return t1 >= t2; case "=": return t1 === t2; case "!=": return t1 !== t2; } }, between: function(d1, d2){ return this.younger(d1) && this.older(d2); }, older: function(date, align){ return this.compare(date, align, "<"); }, olderOrEqual: function(date, align){ return this.compare(date, align, "<="); }, younger: function(date, align){ return this.compare(date, align, ">"); }, youngerOrEqual: function(date, align){ return this.compare(date, align, ">="); }, equal: function(date, align){ return this.compare(date, align, "="); }, notEqual: function(date, align){ return this.compare(date, align, "!="); }, diff: function(d){ var date = datetime(d); var diff = Math.abs(this.time() - date.time()); var diffMonth = Math.abs(this.month() - date.month() + (12 * (this.year() - date.year()))); return { "ms": diff, "second": Math.ceil(diff / 1000), "minute": Math.ceil(diff / (1000 * 60)), "hour": Math.ceil(diff / (1000 * 60 * 60)), "day": Math.ceil(diff / (1000 * 60 * 60 * 24)), "month": diffMonth, "year": Math.floor(diffMonth / 12) } }, distance: function(d, align){ return this.diff(d)[align]; } }) }()); (function() { 'use strict'; Datetime.use({ dayOfYear: function(){ var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; var month = this.month(); var day = this.day(); return dayCount[month] + day + ((month > 1 && this.isLeapYear()) ? 1 : 0); } }) }()); (function() { 'use strict'; Datetime.use({ daysInMonth: function(){ var curr = datetime(this.value); return curr.add(1, 'month').day(1).add(-1, 'day').day(); }, daysInYear: function(){ return this.isLeapYear() ? 366 : 365; }, daysInYearMap: function(){ var result = []; var curr = datetime(this.value); curr.month(0).day(1); for(var i = 0; i < 12; i++) { curr.add(1, 'month').add(-1, 'day'); result.push(curr.day()); curr.day(1).add(1, 'month'); } return result; }, daysInYearObj: function(locale, shortName){ var map = this.daysInYearMap(); var result = {}; var names = Datetime.getLocale(locale || this.locale); map.forEach(function(v, i){ result[names[shortName ? 'monthsShort' : 'months'][i]] = v; }); return result; } }) }()); (function() { 'use strict'; Datetime.use({ decade: function(){ return Math.floor(this.year()/10) * 10; }, decadeStart: function(){ var decade = this.decade(); var result = this.mutable ? this : this.clone(); return result.year(decade).month(0).day(1); }, decadeEnd: function(){ var decade = this.decade() + 9; var result = this.mutable ? this : this.clone(); return result.year(decade).month(11).day(31); }, decadeOfMonth: function(){ var part = this.clone().add(1, "month").day(1).add(-1, 'day').day() / 3; var day = this.day(); if (day <= part) return 1; if (day <= part * 2) return 2; return 3; } }) }()); (function() { 'use strict'; Datetime.useStatic({ from: function(str, format, locale){ var norm, normFormat, fItems, dItems; var iMonth, iDay, iYear, iHour, iMinute, iSecond, iMs; var year, month, day, hour, minute, second, ms; var parsedMonth; var getIndex = function(where, what){ return where.map(function(el){ return el.toLowerCase(); }).indexOf(what.toLowerCase()); } var monthNameToNumber = function(month){ var i = -1; var names = Datetime.getLocale(locale || 'en'); if (Datetime.not(month)) return -1; i = getIndex(names.months, month); if (i === -1 && typeof names["monthsParental"] !== "undefined") { i = getIndex(names.monthsParental, month); } if (i === -1) { month = month.substr(0, 3); i = getIndex(names.monthsShort, month); } return i === -1 ? -1 : i + 1; }; var getPartIndex = function(part){ var parts = { "month": ["M", "mm", "%m"], "day": ["D", "dd", "%d"], "year": ["YY", "YYYY", "yy", "yyyy", "%y"], "hour": ["h", "hh", "%h"], "minute": ["m", "mi", "i", "ii", "%i"], "second": ["s", "ss", "%s"], "ms": ["sss"] } var result = -1, key, index; for(var i = 0; i < parts[part].length; i++) { key = parts[part][i]; index = fItems.indexOf(key); if (index !== -1) { result = index; break; } } return result; } if (Datetime.not(format) || (""+format).trim() === "") { return datetime(); } norm = str.replace(/[\/,.:\s]/g, '-'); normFormat = format.toLowerCase().replace(/[^a-zA-Z0-9%]/g, '-'); fItems = normFormat.split('-'); dItems = norm.split('-'); if (norm.replace(/-/g,"").trim() === "") { throw new Error(Datetime.INVALID_DATE); } iMonth = getPartIndex("month"); iDay = getPartIndex("day"); iYear = getPartIndex("year"); iHour = getPartIndex("hour"); iMinute = getPartIndex("minute"); iSecond = getPartIndex("second"); iMs = getPartIndex("ms"); if (iMonth > -1 && dItems[iMonth]) { if (isNaN(parseInt(dItems[iMonth]))) { dItems[iMonth] = monthNameToNumber(dItems[iMonth]); if (dItems[iMonth] === -1) { iMonth = -1; } } else { parsedMonth = parseInt(dItems[iMonth]); if (parsedMonth < 1 || parsedMonth > 12) { iMonth = -1; } } } else { iMonth = -1; } year = iYear > -1 && dItems[iYear] ? dItems[iYear] : 0; month = iMonth > -1 && dItems[iMonth] ? dItems[iMonth] : 1; day = iDay > -1 && dItems[iDay] ? dItems[iDay] : 1; hour = iHour > -1 && dItems[iHour] ? dItems[iHour] : 0; minute = iMinute > -1 && dItems[iMinute] ? dItems[iMinute] : 0; second = iSecond > -1 && dItems[iSecond] ? dItems[iSecond] : 0; ms = iMs > -1 && dItems[iMs] ? dItems[iMs] : 0; return datetime(year, month-1, day, hour, minute, second, ms); } }) }()); (function() { 'use strict'; var fnFormat = Datetime.prototype.format; var lpad = Datetime.lpad; Datetime.use({ ampm: function(isLowerCase){ var val = this.hour() < 12 ? "AM" : "PM"; return isLowerCase ? val.toLowerCase() : val; }, hour12: function(h, p){ var hour = h; if (arguments.length === 0) { return this.hour() % 12; } p = p || 'am'; if (p.toLowerCase() === "pm") { hour += 12; } return this.hour(hour); }, format: function(format, locale){ var matches, result, h12 = this.hour12(); format = format || Datetime.DEFAULT_FORMAT; matches = { a: "["+this.ampm(true)+"]", A: "["+this.ampm(false)+"]", h: h12, hh: lpad(h12, "0", 2) }; result = format.replace(/(\[[^\]]+])|a|A|h{1,2}/g, function(match, $1){ return $1 || matches[match]; }); return fnFormat.bind(this)(result, locale) } }) }()); (function() { 'use strict'; Datetime.use({ isLeapYear: function(){ var year = this.year(); return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; } }) }()); (function() { 'use strict'; var fnFormat = Datetime.prototype.format; var fnAlign = Datetime.align; var fnAlignEnd = Datetime.alignEnd; Datetime.useStatic({ align: function(d, align){ var date = d instanceof Datetime ? d : datetime(d), result, temp; switch(align) { case "isoWeek": temp = date.isoWeekDay(); result = fnAlign(date, 'day').addDay(-temp + 1); break; // isoWeek default: result = fnAlign.apply(this, [date, align]); } return result; }, alignEnd: function(d, align){ var date = d instanceof Datetime ? d : datetime(d), result, temp; switch(align) { case "isoWeek": temp = date.isoWeekDay(); result = fnAlignEnd(date, 'day').addDay(7 - temp); break; // isoWeek default: result = fnAlignEnd.apply(this, [date, align]); } return result; } }) Datetime.use({ isoWeekDay: function(val){ var wd = (this.weekDay() + 6) % 7 + 1; if (!arguments.length || (Datetime.not(val))) { return wd; } return this.addDay(val - wd); }, format: function(format, locale){ format = format || Datetime.DEFAULT_FORMAT; var matches = { I: this.isoWeekDay() } var result = format.replace(/(\[[^\]]+])|I{1,2}/g, function(match, $1){ return $1 || matches[match]; }) return fnFormat.bind(this)(result, locale) } }) }()); (function() { 'use strict'; Datetime.useStatic({ max: function(){ var arr = [].slice.call(arguments); return arr.map(function(el){ return datetime(el); }).sort(function(a, b){ return b.time() - a.time() })[0]; } }); Datetime.use({ max: function(){ return Datetime.max.apply(this, [this].concat([].slice.call(arguments))); } }); }()); (function() { 'use strict'; Datetime.useStatic({ min: function(){ var arr = [].slice.call(arguments); return arr.map(function(el){ return datetime(el); }).sort(function(a, b){ return a.time() - b.time() })[0]; } }); Datetime.use({ min: function(){ return Datetime.min.apply(this, [this].concat([].slice.call(arguments))); } }) }()); (function() { 'use strict'; var fnAlign = Datetime.align; var fnAlignEnd = Datetime.alignEnd; var fnAdd = Datetime.prototype.add; Datetime.useStatic({ align: function(d, align){ var date = d instanceof Datetime ? d : datetime(d), result; switch(align) { case "quarter": result = Datetime.align(date, 'day').day(1).month(date.quarter() * 3 - 3); break; //quarter default: result = fnAlign.apply(this, [date, align]); } return result; }, alignEnd: function(d, align){ var date = d instanceof Datetime ? d : datetime(d), result; switch(align) { case "quarter": result = Datetime.align(date, 'quarter').add(3, 'month').add(-1, 'ms'); break; //quarter default: result = fnAlignEnd.apply(this, [date, align]); } return result; } }) Datetime.use({ quarter: function(){ var month = this.month(); if (month <= 2) return 1; if (month <= 5) return 2; if (month <= 8) return 3; return 4; }, add: function(val, to){ if (to === "quarter") { return this.month(this.month() + val * 3); } return fnAdd.bind(this)(val, to); }, addQuarter: function(v){ return this.add(v, "quarter"); } }) }()); (function() { 'use strict'; Datetime.useStatic({ sort: function(arr, opt){ var result, _arr; var o = {}; if (typeof opt === "string" || typeof opt !== "object" || Datetime.not(opt)) { o.format = Datetime.DEFAULT_FORMAT; o.dir = opt && opt.toUpperCase() === "DESC" ? "DESC" : "ASC"; o.returnAs = "datetime"; } else { o.format = opt.format || Datetime.DEFAULT_FORMAT; o.dir = (opt.dir || "ASC").toUpperCase(); o.returnAs = opt.format ? "string" : opt.returnAs || "datetime"; } _arr = arr.map(function(el){ return datetime(el); }).sort(function(a, b){ return a.valueOf() - b.valueOf(); }); if (o.dir === "DESC") { _arr.reverse(); } switch (o.returnAs) { case "string": result = _arr.map(function(el){ return el.format(o.format) }); break; case "date": result = _arr.map(function(el){ return el.val(); }); break; default: result = _arr; } return result; } }) }()); (function() { 'use strict'; var REGEX_FORMAT_STRFTIME = /(%[a-z])/gi; var DEFAULT_FORMAT_STRFTIME = "%Y-%m-%dT%H:%M:%S.%Q%t"; var lpad = Datetime.lpad; Datetime.use({ strftime: function(fmt, locale){ var format = fmt || DEFAULT_FORMAT_STRFTIME; var names = Datetime.getLocale(locale || this.locale); var year = this.year(), year2 = this.year2(), month = this.month(), day = this.day(), weekDay = this.weekDay(); var hour = this.hour(), hour12 = this.hour12(), minute = this.minute(), second = this.second(), ms = this.ms(), time = this.time(); var aDay = lpad(day, "0", 2), aMonth = lpad(month + 1, "0", 2), aHour = lpad(hour, "0", 2), aHour12 = lpad(hour12, "0", 2), aMinute = lpad(minute, "0", 2), aSecond = lpad(second, "0", 2), aMs = lpad(ms, "0", 3); var that = this; var thursday = function(){ var target = datetime(that.value); target.day(that.day() - ((that.weekDay() + 6) % 7) + 3); return target; }; var matches = { '%a': names.weekdaysShort[weekDay], '%A': names.weekdays[weekDay], '%b': names.monthsShort[month], '%h': names.monthsShort[month], '%B': names.months[month], '%c': this.toString().substring(0, this.toString().indexOf(" (")), '%C': this.century(), '%d': aDay, '%D': [aDay, aMonth, year].join("/"), '%e': day, '%F': [year, aMonth, aDay].join("-"), '%G': thursday().year(), '%g': (""+thursday().year()).slice(2), '%H': aHour, '%I': aHour12, '%j': lpad(this.dayOfYear(), "0", 3), '%k': aHour, '%l': aHour12, '%m': aMonth, '%n': month + 1, '%M': aMinute, '%p': this.ampm(), '%P': this.ampm(true), '%s': Math.round(time / 1000), '%S': aSecond, '%u': this.isoWeekDay(), '%V': this.isoWeekNumber(), '%w': weekDay, '%x': this.toLocaleDateString(), '%X': this.toLocaleTimeString(), '%y': year2, '%Y': year, '%z': this.timezone().replace(":", ""), '%Z': this.timezoneName(), '%r': [aHour12, aMinute, aSecond].join(":") + " " + this.ampm(), '%R': [aHour, aMinute].join(":"), "%T": [aHour, aMinute, aSecond].join(":"), "%Q": aMs, "%q": ms, "%t": this.timezone() }; return format.replace(REGEX_FORMAT_STRFTIME, function(match){ return (matches[match] === 0 || matches[match] ? matches[match] : match); }); } }); }()); (function() { 'use strict'; var fnFormat = Datetime.prototype.format; Datetime.use({ utcOffset: function(){ return this.value.getTimezoneOffset(); }, timezone: function(){ return this.toTimeString().replace(/.+GMT([+-])(\d{2})(\d{2}).+/, '$1$2:$3'); }, timezoneName: function(){ return this.toTimeString().replace(/.+\((.+?)\)$/, '$1'); }, format: function(format, locale){ format = format || Datetime.DEFAULT_FORMAT; var matches = { Z: this.utcMode ? "Z" : this.timezone(), ZZ: this.timezone().replace(":", ""), ZZZ: "[GMT]"+this.timezone(), z: this.timezoneName() } var result = format.replace(/(\[[^\]]+])|Z{1,3}|z/g, function(match, $1){ return $1 || matches[match]; }) return fnFormat.bind(this)(result, locale) } }) }()); (function() { 'use strict'; Datetime.useStatic({ isToday: function(date){ var d = datetime(date).align("day"); var c = datetime().align('day'); return d.time() === c.time(); } }) Datetime.use({ isToday: function(){ return Datetime.isToday(this); }, today: function(){ var now = datetime(); if (!this.mutable) { return now; } return this.val(now.val()); } }) }()); (function() { 'use strict'; Datetime.useStatic({ isTomorrow: function(date){ var d = datetime(date).align("day"); var c = datetime().align('day').add(1, 'day'); return d.time() === c.time(); } }); Datetime.use({ isTomorrow: function(){ return Datetime.isTomorrow(this); }, tomorrow: function(){ if (!this.mutable) { return this.clone().add(1, 'day'); } return this.add(1, 'day'); } }); }()); (function() { 'use strict'; Datetime.use({ toDateString: function(){ return this.value.toDateString(); }, toISOString: function(){ return this.value.toISOString(); }, toJSON: function(){ return this.value.toJSON(); }, toGMTString: function(){ return this.value.toGMTString(); }, toLocaleDateString: function(){ return this.value.toLocaleDateString(); }, toLocaleString: function(){ return this.value.toLocaleString(); }, toLocaleTimeString: function(){ return this.value.toLocaleTimeString(); }, toTimeString: function(){ return this.value.toTimeString(); }, toUTCString: function(){ return this.value.toUTCString(); }, toDate: function(){ return new Date(this.value); } }); }()); (function() { 'use strict'; Datetime.useStatic({ timestamp: function(){ return new Date().getTime() / 1000; } }) Datetime.use({ unix: function(val) { var _val; if (!arguments.length || (Datetime.not(val))) { return Math.floor(this.valueOf() / 1000) } _val = val * 1000; if (this.mutable) { return this.time(_val); } return datetime(this.value).time(_val); }, timestamp: function(){ return this.unix(); } }); }()); (function() { 'use strict'; var fnFormat = Datetime.prototype.format; var lpad = Datetime.lpad; Datetime.use({ weekNumber: function (weekStart) { var nYear, nday, newYear, day, daynum, weeknum; weekStart = +weekStart || 0; newYear = datetime(this.year(), 0, 1); day = newYear.weekDay() - weekStart; day = (day >= 0 ? day : day + 7); daynum = Math.floor( (this.time() - newYear.time() - (this.utcOffset() - newYear.utcOffset()) * 60000) / 86400000 ) + 1; if(day < 4) { weeknum = Math.floor((daynum + day - 1) / 7) + 1; if(weeknum > 52) { nYear = datetime(this.year() + 1, 0, 1); nday = nYear.weekDay() - weekStart; nday = nday >= 0 ? nday : nday + 7; weeknum = nday < 4 ? 1 : 53; } } else { weeknum = Math.floor((daynum + day - 1) / 7); } return weeknum; }, isoWeekNumber: function(){ return this.weekNumber(1); }, weeksInYear: function(weekStart){ var curr = datetime(this.value); return curr.month(11).day(31).weekNumber(weekStart); }, format: function(format, locale){ var matches, result, wn = this.weekNumber(), wni = this.isoWeekNumber(); format = format || Datetime.DEFAULT_FORMAT; matches = { W: wn, WW: lpad(wn, "0", 2), WWW: wni, WWWW: lpad(wni, "0", 2) }; result = format.replace(/(\[[^\]]+])|W{1,4}/g, function(match, $1){ return $1 || matches[match]; }); return fnFormat.bind(this)(result, locale) } }) }()); (function() { 'use strict'; Datetime.useStatic({ isYesterday: function(date){ var d = datetime(date).align("day"); var c = datetime().align('day').add(-1, 'day'); return d.time() === c.time(); } }); Datetime.use({ isYesterday: function(){ return Datetime.isYesterday(this); }, yesterday: function(){ if (!this.mutable) { return this.clone().add(-1, 'day'); } return this.add(-1, 'day'); } }) }()); (function() { 'use strict'; var getLocale = Datetime.getLocale; Datetime.getLocale = function(locale){ var data; if (!Metro) { locale = 'en'; return getLocale.call(this, locale); } if (!Metro.locales[locale]) { locale = "en-US"; } data = Metro.locales[locale]['calendar']; return { months: data.months.filter( function(el, i){ return i < 12} ), monthsShort: data.months.filter( function(el, i){ return i > 11} ), weekdays: data.days.filter( function(el, i){ return i < 7} ), weekdaysShort: data.days.filter( function(el, i){ return i > 13} ), weekdaysMin: data.days.filter( function(el, i){ return i > 6 && i < 14} ), weekStart: data.weekStart } } }()); /*! * Cake string library 1.0.0 * https://github.com/olton/cake * * Copyright 2020-2021 Serhii Pimenov * Released under the MIT license */ (function () { 'use strict'; var isNull = function isNull(val) { return val === undefined || val === null; }; /** * A regular expression string matching digits */ var digit = '\\d'; /** * A regular expression string matching whitespace */ var whitespace = "\\s\\uFEFF\\xA0"; /** * A regular expression string matching diacritical mark */ var diacriticalMark = "\\u0300-\\u036F\\u1AB0-\\u1AFF\\u1DC0-\\u1DFF\\u20D0-\\u20FF\\uFE20-\\uFE2F"; /** * A regular expression to match the General Punctuation Unicode block */ var generalPunctuationBlock = "\\u2000-\\u206F"; /** * A regular expression to match non characters from from Basic Latin and Latin-1 Supplement Unicode blocks */ var nonCharacter = '\\x00-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7b-\\xBF\\xD7\\xF7'; /** * A regular expression to match the dingbat Unicode block */ var dingbatBlock = "\\u2700-\\u27BF"; /** * A regular expression string that matches lower case letters: LATIN */ var lowerCaseLetter = "a-z\\xB5\\xDF-\\xF6\\xF8-\\xFF\\u0101\\u0103\\u0105\\u0107\\u0109\\u010B\\u010D\\u010F\\u0111\\u0113\\u0115\\u0117\\u0119\\u011B\\u011D\\u011F\\u0121\\u0123\\u0125\\u0127\\u0129\\u012B\\u012D\\u012F\\u0131\\u0133\\u0135\\u0137\\u0138\\u013A\\u013C\\u013E\\u0140\\u0142\\u0144\\u0146\\u0148\\u0149\\u014B\\u014D\\u014F\\u0151\\u0153\\u0155\\u0157\\u0159\\u015B\\u015D\\u015F\\u0161\\u0163\\u0165\\u0167\\u0169\\u016B\\u016D\\u016F\\u0171\\u0173\\u0175\\u0177\\u017A\\u017C\\u017E-\\u0180\\u0183\\u0185\\u0188\\u018C\\u018D\\u0192\\u0195\\u0199-\\u019B\\u019E\\u01A1\\u01A3\\u01A5\\u01A8\\u01AA\\u01AB\\u01AD\\u01B0\\u01B4\\u01B6\\u01B9\\u01BA\\u01BD-\\u01BF\\u01C6\\u01C9\\u01CC\\u01CE\\u01D0\\u01D2\\u01D4\\u01D6\\u01D8\\u01DA\\u01DC\\u01DD\\u01DF\\u01E1\\u01E3\\u01E5\\u01E7\\u01E9\\u01EB\\u01ED\\u01EF\\u01F0\\u01F3\\u01F5\\u01F9\\u01FB\\u01FD\\u01FF\\u0201\\u0203\\u0205\\u0207\\u0209\\u020B\\u020D\\u020F\\u0211\\u0213\\u0215\\u0217\\u0219\\u021B\\u021D\\u021F\\u0221\\u0223\\u0225\\u0227\\u0229\\u022B\\u022D\\u022F\\u0231\\u0233-\\u0239\\u023C\\u023F\\u0240\\u0242\\u0247\\u0249\\u024B\\u024D\\u024F"; /** * A regular expression string that matches upper case letters: LATIN */ var upperCaseLetter = "\\x41-\\x5a\\xc0-\\xd6\\xd8-\\xde\\u0100\\u0102\\u0104\\u0106\\u0108\\u010a\\u010c\\u010e\\u0110\\u0112\\u0114\\u0116\\u0118\\u011a\\u011c\\u011e\\u0120\\u0122\\u0124\\u0126\\u0128\\u012a\\u012c\\u012e\\u0130\\u0132\\u0134\\u0136\\u0139\\u013b\\u013d\\u013f\\u0141\\u0143\\u0145\\u0147\\u014a\\u014c\\u014e\\u0150\\u0152\\u0154\\u0156\\u0158\\u015a\\u015c\\u015e\\u0160\\u0162\\u0164\\u0166\\u0168\\u016a\\u016c\\u016e\\u0170\\u0172\\u0174\\u0176\\u0178\\u0179\\u017b\\u017d\\u0181\\u0182\\u0184\\u0186\\u0187\\u0189-\\u018b\\u018e-\\u0191\\u0193\\u0194\\u0196-\\u0198\\u019c\\u019d\\u019f\\u01a0\\u01a2\\u01a4\\u01a6\\u01a7\\u01a9\\u01ac\\u01ae\\u01af\\u01b1-\\u01b3\\u01b5\\u01b7\\u01b8\\u01bc\\u01c4\\u01c5\\u01c7\\u01c8\\u01ca\\u01cb\\u01cd\\u01cf\\u01d1\\u01d3\\u01d5\\u01d7\\u01d9\\u01db\\u01de\\u01e0\\u01e2\\u01e4\\u01e6\\u01e8\\u01ea\\u01ec\\u01ee\\u01f1\\u01f2\\u01f4\\u01f6-\\u01f8\\u01fa\\u01fc\\u01fe\\u0200\\u0202\\u0204\\u0206\\u0208\\u020a\\u020c\\u020e\\u0210\\u0212\\u0214\\u0216\\u0218\\u021a\\u021c\\u021e\\u0220\\u0222\\u0224\\u0226\\u0228\\u022a\\u022c\\u022e\\u0230\\u0232\\u023a\\u023b\\u023d\\u023e\\u0241\\u0243-\\u0246\\u0248\\u024a\\u024c\\u024e"; /** * Regular expression to match whitespaces from the left side */ var REGEXP_TRIM_LEFT = new RegExp('^[' + whitespace + ']+'); /** * Regular expression to match whitespaces from the right side */ var REGEXP_TRIM_RIGHT = new RegExp('[' + whitespace + ']+$'); /** * Regular expression to match digit characters */ var REGEXP_DIGIT = new RegExp('^' + digit + '+$'); /** * Regular expression to match HTML special characters. */ var REGEXP_HTML_SPECIAL_CHARACTERS = /[<>&"'`]/g; var REGEXP_TAGS = /(<([^>]+)>)/ig; /** * Regular expression to match Unicode words */ var REGEXP_WORD = new RegExp('(?:[' + upperCaseLetter + '][' + diacriticalMark + ']*)?(?:[' + lowerCaseLetter + '][' + diacriticalMark + ']*)+|\ (?:[' + upperCaseLetter + '][' + diacriticalMark + ']*)+(?![' + lowerCaseLetter + '])|\ [' + digit + ']+|\ [' + dingbatBlock + ']|\ [^' + nonCharacter + generalPunctuationBlock + whitespace + ']+', 'g'); /** * Regular expression to match words from Basic Latin and Latin-1 Supplement blocks */ var REGEXP_LATIN_WORD = /[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g; /** * Regular expression to match alpha characters */ var REGEXP_ALPHA = new RegExp('^(?:[' + lowerCaseLetter + upperCaseLetter + '][' + diacriticalMark + ']*)+$'); /** * Regular expression to match alpha and digit characters */ var REGEXP_ALPHA_DIGIT = new RegExp('^((?:[' + lowerCaseLetter + upperCaseLetter + '][' + diacriticalMark + ']*)|[' + digit + '])+$'); /** * Regular expression to match Extended ASCII characters, i.e. the first 255 */ var REGEXP_EXTENDED_ASCII = /^[\x01-\xFF]*$/; function nvl(val, def) { return isNull(val) ? def : val; } function toStr(val) { var def = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ""; if (isNull(val)) return def; if (typeof val === "string") return val; if (Array.isArray(val)) return val.join(""); return JSON.stringify(val); } /* * Split string to words. You can set specified patter to split * */ function words(s, pattern, flags) { var regexp; if (isNull(pattern)) { regexp = REGEXP_EXTENDED_ASCII.test(s) ? REGEXP_LATIN_WORD : REGEXP_WORD; } else if (pattern instanceof RegExp) { regexp = pattern; } else { regexp = new RegExp(pattern, nvl(flags, '')); } return nvl(toStr(s).match(regexp), []); } function capitalize(s, strong) { var _s = toStr(s); var last = _s.substr(1); return _s.substr(0, 1).toUpperCase() + (strong ? last.toLowerCase() : last); } function camelCase(s) { return words(toStr(s)).map(function (el, i) { return i === 0 ? el.toLowerCase() : capitalize(el); }).join(""); } function dashedName(s) { return words(toStr(s)).map(function (el) { return el.toLowerCase(); }).join("-"); } function decapitalize(s) { var _s = toStr(s); return _s.substr(0, 1).toLowerCase() + _s.substr(1); } function kebab(s) { return words(toStr(s)).map(function (el) { return el.toLowerCase(); }).join("-"); } function lower(s) { return toStr(s).toLowerCase(); } /* * Split string to chars array with ignores * */ function chars(s) { var ignore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; return toStr(s).split("").filter(function (el) { return !ignore.includes(el); }); } function reverse(s, ignore) { return chars(toStr(s), ignore).reverse().join(""); } function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; }; } else { _typeof = function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticP