1
(function(global, factory) {
2
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
typeof define === 'function' && define.amd ? define(factory) :
4
global.moment = factory();
10
"k": "YYYY-MM-DD hh:mm",
11
"kk": "YYYY年MM月DD日 hh点mm分",
12
"kkk": "YYYY年MM月DD日 hh点mm分 q",
13
"f": "YYYY-MM-DD hh:mm:ss",
14
"ff": "YYYY年MM月DD日 hh点mm分ss秒",
15
"fff": "YYYY年MM月DD日 hh点mm分ss秒 星期w",
20
const _SECONDS = 1000;
21
const _MINUTES = 1000 * 60;
22
const _HOURS = 1000 * 60 * 60;
23
const _DAYS = 1000 * 60 * 60 * 24;
24
const _WEEKS = _DAYS * 7;
25
const _YEARS = _DAYS * 365;
26
const MSE = new Date(1970, 0, 1, 0, 0, 0).getTime();
28
const WEEK = ['日', '一', '二', '三', '四', '五', '六'];
29
const DAY_STRING = ['上午', '下午'];
30
let _moment = function() {
31
Utils.initMoment(this, ...arguments);
35
initMoment(moment_obj, arg_1, type) {
36
let _date = new Date(),date_bak = _date;
37
if (arg_1 != undefined) {
38
if (Utils.isNumber(arg_1)) {
39
if (arg_1 < 9999999999) arg_1 = arg_1 * 1000;
41
} else if (Utils.isArray(arg_1)) {
42
Utils.padMonth(arg_1);
43
_date = new Date(...arg_1);
44
} else if (Utils.isDate(arg_1)) {
46
} else if (Utils.isString(arg_1)) {
47
_date = Utils.parse(arg_1);
48
} else if (arg_1 instanceof _moment) {
52
moment_obj._date = _date;
53
if(date_bak === _date&&moment_obj.timeDelay!=0){
54
moment_obj.add(moment_obj.timeDelay,moment.TIME);
58
let aspNetJsonRegex = /^(\d{4})\-?(\d{2})\-?(\d{2})\s?\:?(\d{2})?\:?(\d{2})?\:?(\d{2})?$/i;
59
var matched = aspNetJsonRegex.exec(str);
60
if (matched !== null) {
62
Utils.padMonth(matched);
63
Utils.popUndefined(matched);
64
return new Date(...matched);
66
let date = new Date(str);
67
if(date=="Invalid Date"){
68
console.error("Invalid date parse from \""+str+"\"");
75
if (arr.length > 0 && arr[arr.length - 1] == undefined) {
77
return Utils.popUndefined(arr);
83
if (arr.length > 1 && arr[1] > 0) arr[1] -= 1;
86
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
88
format(date, formatStr) {
90
str = str.replace(/yyyy|YYYY/, date.getFullYear());
91
str = str.replace(/yy|YY/, (date.getYear() % 100) > 8 ? (date.getYear() % 100).toString() : '0' + (date.getYear() % 100));
92
str = str.replace(/MM/, date.getMonth() > 8 ? (date.getMonth() + 1).toString() : ('0' + (date.getMonth() + 1)));
93
str = str.replace(/M/g, (date.getMonth() + 1));
94
str = str.replace(/w|W/g, WEEK[date.getDay()]);
95
str = str.replace(/dd|DD/, date.getDate() > 9 ? date.getDate().toString() : '0' + date.getDate());
96
str = str.replace(/d|D/g, date.getDate());
97
str = str.replace(/hh|HH/, date.getHours() > 9 ? date.getHours().toString() : '0' + date.getHours());
98
str = str.replace(/h|H/g, date.getHours());
99
str = str.replace(/mm/, date.getMinutes() > 9 ? date.getMinutes().toString() : '0' + date.getMinutes());
100
str = str.replace(/m/g, date.getMinutes());
101
str = str.replace(/ss|SS/, date.getSeconds() > 9 ? date.getSeconds().toString() : '0' + date.getSeconds());
102
str = str.replace(/s|S/g, date.getSeconds());
103
str = str.replace(/q|Q/g, date.getHours() > 12 ? DAY_STRING[1] : DAY_STRING[0]);
107
return Math.floor(date.getTime() / 1000);
110
return Math.floor((date.getTime() - MSE) / _DAYS);
113
return Math.floor((date.getTime() - MSE) / _HOURS);
116
return date.getYear() * 12 + date.getMonth() + 1;
119
return Object.prototype.toString.call(input) === '[object Object]';
122
return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
125
return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
128
return input instanceof Number || Object.prototype.toString.call(input) === '[object Number]';
131
return input instanceof String || Object.prototype.toString.call(input) === '[object String]';
135
if (hasOwnProp(b, i)) {
140
if (hasOwnProp(b, 'toString')) {
141
a.toString = b.toString;
144
if (hasOwnProp(b, 'valueOf')) {
145
a.valueOf = b.valueOf;
151
return function(value) {
152
if (value != undefined) {
154
Date.prototype["set" + unit].call(this._date, value);
157
return Date.prototype["get" + unit].call(this._date);
165
function hasOwnProp(a, b) {
166
return Object.prototype.hasOwnProperty.call(a, b);
170
_moment.prototype = {
175
let v = this.isValid();
176
if(v!==true)return v;
179
let formatStr = FORMAT_LIST[str] || str;
180
return Utils.format(m._date, formatStr);
183
let v = this.isValid();
184
if(v!==true)return v;
185
return this._date.toString();
188
let v = this.isValid();
189
if(v!==true)return v;
190
return this._date.toISOString();
193
let v = this.isValid();
194
if(v!==true)return v;
196
type = type || moment.DAY;
199
if(v!==true)return v;
202
return Utils.getHours(m._date) - Utils.getHours(_m._date);
204
return Utils.getDays(m._date) - Utils.getDays(_m._date);
206
return Utils.getMonths(m._date) - Utils.getMonths(_m._date);
208
return m._date.getYear() - _m._date.getYear();
212
getWeekOfYear(weekStart){
214
if(weekStart&&weekStart==moment.MONDAY){
217
let _date = this._date;
218
let year = _date.getFullYear();
219
let firstDay = new Date(year, 0, 1);
220
let firstWeekDays = 7 - firstDay.getDay() + diff;
221
let dayOfYear = (((new Date(year, _date.getMonth(), _date.getDate())) - firstDay) / (24 * 3600 * 1000)) + 1;
222
return Math.ceil((dayOfYear - firstWeekDays) / 7) + 1;
224
getWeekOfMonth(weekStart) {
226
if(weekStart&&weekStart==moment.MONDAY){
229
var dayOfWeek = this.day();
230
var day = this.date();
231
return Math.ceil((day - dayOfWeek - 1) / 7) + ((dayOfWeek >= weekStart) ? 1 : 0);
234
let v = this.isValid();
235
if(v!==true)return v;
236
return Utils.isLeapYear(this.year());
239
let v = this.isValid();
240
if(v!==true)return v;
241
return Utils.timestamp(this._date);
244
let v = this.isValid();
245
if(v!==true)return v;
246
return Utils.timestamp(this._date);
249
let v = this.isValid();
250
if(v!==true)return v;
251
return Utils.timestamp(this._date);
254
let v = this.isValid();
255
if(v!==true)return v;
257
if (num == undefined) {
258
return m._date.getMonth() + 1;
261
num = m._date.setMonth(num - 1);
265
let v = this.isValid();
266
if(v!==true)return v;
269
type = type || moment.DAY;
273
m.time(m.time() + (num * _DAYS));
276
let month_add = m.month() + num;
277
let year_add = Math.floor(month_add / 12);
278
month_add = month_add % 12;
279
m.add(year_add, moment.YEAR);
283
m.year(m.year() + num);
286
m.time(m.time() + (num * _WEEKS));
289
m.time(m.time() + (num * _HOURS));
292
m.time(m.time() + (num * _MINUTES));
295
m.time(m.time() + (num * _SECONDS));
298
m.time(m.time() + (num));
304
let v = this.isValid();
305
if(v!==true)return v;
307
type = type || moment.DAY;
311
m.add(-1, moment.SECOND);
318
let v = this.isValid();
319
if(v!==true)return v;
321
type = type || moment.DAY;
331
m.startOf(moment.DAY);
334
m.startOf(moment.DAY);
335
set=set||moment.SUNDAY;
336
let startDay = set==moment.SUNDAY?0:1;
337
m.add(-m.day()+startDay,moment.DAY);
342
m.startOf(moment.DAY);
345
m.time(Math.floor((m.time()) / _HOURS) * _HOURS);
351
return Utils.isDate(this._date)?true:"Invalid Date";
355
let momentPrototype__proto = _moment.prototype;
362
"milliseconds": "Milliseconds",
363
"seconds": "Seconds",
364
"minutes": "Minutes",
368
for (let unit in methods) {
369
momentPrototype__proto[unit] = Utils.makeGetSet(methods[unit]);
372
let moment = function(param) {
373
if(param instanceof _moment){
375
}else if (Utils.isObject(param)) {
377
if (param.formatString && Utils.isObject(param.formatString)) {
378
Utils.extend(FORMAT_LIST, param.formatString);
381
_moment.prototype.timeDelay = moment(param.now).time() - moment().time();
384
return new _moment(param);
388
moment.config = function(param) {
389
if (param.formatString && Utils.isObject(param.formatString)) {
390
Utils.extend(FORMAT_LIST, param.formatString);
393
_moment.prototype.timeDelay = moment(param.now).time() - moment().time();