增加基本项目配置

This commit is contained in:
Gao xiaosong
2020-03-15 13:59:43 +08:00
commit 397082cdaf
1117 changed files with 105700 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
import { FORMAT_DEFAULT } from '../../constant';
export default (function (o, c, d) {
// locale needed later
var proto = c.prototype;
var oldFormat = proto.format;
d.en.ordinal = function (number) {
var s = ['th', 'st', 'nd', 'rd'];
var v = number % 100;
return "[" + number + (s[(v - 20) % 10] || s[v] || s[0]) + "]";
}; // extend en locale here
proto.format = function (formatStr) {
var _this = this;
var locale = this.$locale();
var utils = this.$utils();
var str = formatStr || FORMAT_DEFAULT;
var result = str.replace(/\[([^\]]+)]|Q|wo|ww|w|gggg|Do|X|x|k{1,2}|S/g, function (match) {
switch (match) {
case 'Q':
return Math.ceil((_this.$M + 1) / 3);
case 'Do':
return locale.ordinal(_this.$D);
case 'gggg':
return _this.weekYear();
case 'wo':
return locale.ordinal(_this.week(), 'W');
// W for week
case 'w':
case 'ww':
return utils.s(_this.week(), match === 'w' ? 1 : 2, '0');
case 'k':
case 'kk':
return utils.s(String(_this.$H === 0 ? 24 : _this.$H), match === 'k' ? 1 : 2, '0');
case 'X':
return Math.floor(_this.$d.getTime() / 1000);
case 'x':
return _this.$d.getTime();
default:
return match;
}
});
return oldFormat.bind(this)(result);
};
});
+61
View File
@@ -0,0 +1,61 @@
export default (function (o, c) {
// locale needed later
var proto = c.prototype;
proto.$g = function (input, get, set) {
if (this.$utils().u(input)) return this[get];
return this.$set(set, input);
};
proto.set = function (string, _int) {
return this.$set(string, _int);
};
var oldStartOf = proto.startOf;
proto.startOf = function (units, startOf) {
this.$d = oldStartOf.bind(this)(units, startOf).toDate();
this.init();
return this;
};
var oldAdd = proto.add;
proto.add = function (number, units) {
this.$d = oldAdd.bind(this)(number, units).toDate();
this.init();
return this;
};
var oldLocale = proto.locale;
proto.locale = function (preset, object) {
if (!preset) return this.$L;
this.$L = oldLocale.bind(this)(preset, object).$L;
return this;
};
var oldDaysInMonth = proto.daysInMonth;
proto.daysInMonth = function () {
return oldDaysInMonth.bind(this.clone())();
};
var oldIsSame = proto.isSame;
proto.isSame = function (that, units) {
return oldIsSame.bind(this.clone())(that, units);
};
var oldIsBefore = proto.isBefore;
proto.isBefore = function (that, units) {
return oldIsBefore.bind(this.clone())(that, units);
};
var oldIsAfter = proto.isAfter;
proto.isAfter = function (that, units) {
return oldIsAfter.bind(this.clone())(that, units);
};
});
+21
View File
@@ -0,0 +1,21 @@
import { FORMAT_DEFAULT } from '../../constant';
export default (function (o, c) {
// locale needed later
var proto = c.prototype;
var oldFormat = proto.format; // extend en locale here
proto.format = function (formatStr) {
var _this = this;
var yearBias = 543;
var str = formatStr || FORMAT_DEFAULT;
var result = str.replace(/(\[[^\]]+])|BBBB|BB/g, function (match, a) {
var _this$$utils;
var year = String(_this.$y + yearBias);
var args = match === 'BB' ? [year.slice(-2), 2] : [year, 4];
return a || (_this$$utils = _this.$utils()).s.apply(_this$$utils, args.concat(['0']));
});
return oldFormat.bind(this)(result);
};
});
+26
View File
@@ -0,0 +1,26 @@
export default (function (o, c, d) {
var LT = 'h:mm A';
var L = 'MM/DD/YYYY';
var calendarFormat = {
lastDay: "[Yesterday at] " + LT,
sameDay: "[Today at] " + LT,
nextDay: "[Tomorrow at] " + LT,
nextWeek: "dddd [at] " + LT,
lastWeek: "[Last] dddd [at] " + LT,
sameElse: L
};
var proto = c.prototype;
proto.calendar = function (referenceTime, formats) {
var format = formats || this.$locale().calendar || calendarFormat;
var referenceStartOfDay = d(referenceTime || undefined).startOf('d');
var diff = this.diff(referenceStartOfDay, 'd', true);
var sameElse = 'sameElse';
/* eslint-disable no-nested-ternary */
var retVal = diff < -6 ? sameElse : diff < -1 ? 'lastWeek' : diff < 0 ? 'lastDay' : diff < 1 ? 'sameDay' : diff < 2 ? 'nextDay' : diff < 7 ? 'nextWeek' : sameElse;
/* eslint-enable no-nested-ternary */
return this.format(format[retVal] || calendarFormat[retVal]);
};
});
+241
View File
@@ -0,0 +1,241 @@
var formattingTokens = /(\[[^[]*\])|([-:/.()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g;
var match1 = /\d/; // 0 - 9
var match2 = /\d\d/; // 00 - 99
var match3 = /\d{3}/; // 000 - 999
var match4 = /\d{4}/; // 0000 - 9999
var match1to2 = /\d\d?/; // 0 - 99
var matchUpperCaseAMPM = /[AP]M/;
var matchLowerCaseAMPM = /[ap]m/;
var matchSigned = /[+-]?\d+/; // -inf - inf
var matchOffset = /[+-]\d\d:?\d\d/; // +00:00 -00:00 +0000 or -0000
var matchWord = /\d*[^\s\d-:/.()]+/; // Word
var locale;
function offsetFromString(string) {
var parts = string.match(/([+-]|\d\d)/g);
var minutes = +(parts[1] * 60) + +parts[2];
return minutes === 0 ? 0 : parts[0] === '+' ? -minutes : minutes; // eslint-disable-line no-nested-ternary
}
var addInput = function addInput(property) {
return function (input) {
this[property] = +input;
};
};
var zoneExpressions = [matchOffset, function (input) {
var zone = this.zone || (this.zone = {});
zone.offset = offsetFromString(input);
}];
var expressions = {
A: [matchUpperCaseAMPM, function (input) {
this.afternoon = input === 'PM';
}],
a: [matchLowerCaseAMPM, function (input) {
this.afternoon = input === 'pm';
}],
S: [match1, function (input) {
this.milliseconds = +input * 100;
}],
SS: [match2, function (input) {
this.milliseconds = +input * 10;
}],
SSS: [match3, function (input) {
this.milliseconds = +input;
}],
s: [match1to2, addInput('seconds')],
ss: [match1to2, addInput('seconds')],
m: [match1to2, addInput('minutes')],
mm: [match1to2, addInput('minutes')],
H: [match1to2, addInput('hours')],
h: [match1to2, addInput('hours')],
HH: [match1to2, addInput('hours')],
hh: [match1to2, addInput('hours')],
D: [match1to2, addInput('day')],
DD: [match2, addInput('day')],
Do: [matchWord, function (input) {
var _locale = locale,
ordinal = _locale.ordinal;
var _input$match = input.match(/\d+/);
this.day = _input$match[0];
if (!ordinal) return;
for (var i = 1; i <= 31; i += 1) {
if (ordinal(i).replace(/\[|\]/g, '') === input) {
this.day = i;
}
}
}],
M: [match1to2, addInput('month')],
MM: [match2, addInput('month')],
MMM: [matchWord, function (input) {
var _locale2 = locale,
months = _locale2.months,
monthsShort = _locale2.monthsShort;
var matchIndex = monthsShort ? monthsShort.findIndex(function (month) {
return month === input;
}) : months.findIndex(function (month) {
return month.substr(0, 3) === input;
});
if (matchIndex < 0) {
throw new Error();
}
this.month = matchIndex + 1;
}],
MMMM: [matchWord, function (input) {
var _locale3 = locale,
months = _locale3.months;
var matchIndex = months.indexOf(input);
if (matchIndex < 0) {
throw new Error();
}
this.month = matchIndex + 1;
}],
Y: [matchSigned, addInput('year')],
YY: [match2, function (input) {
input = +input;
this.year = input + (input > 68 ? 1900 : 2000);
}],
YYYY: [match4, addInput('year')],
Z: zoneExpressions,
ZZ: zoneExpressions
};
function correctHours(time) {
var afternoon = time.afternoon;
if (afternoon !== undefined) {
var hours = time.hours;
if (afternoon) {
if (hours < 12) {
time.hours += 12;
}
} else if (hours === 12) {
time.hours = 0;
}
delete time.afternoon;
}
}
function makeParser(format) {
var array = format.match(formattingTokens);
var length = array.length;
for (var i = 0; i < length; i += 1) {
var token = array[i];
var parseTo = expressions[token];
var regex = parseTo && parseTo[0];
var parser = parseTo && parseTo[1];
if (parser) {
array[i] = {
regex: regex,
parser: parser
};
} else {
array[i] = token.replace(/^\[|\]$/g, '');
}
}
return function (input) {
var time = {};
for (var _i = 0, start = 0; _i < length; _i += 1) {
var _token = array[_i];
if (typeof _token === 'string') {
start += _token.length;
} else {
var _regex = _token.regex,
_parser = _token.parser;
var part = input.substr(start);
var match = _regex.exec(part);
var value = match[0];
_parser.call(time, value);
input = input.replace(value, '');
}
}
correctHours(time);
return time;
};
}
var parseFormattedInput = function parseFormattedInput(input, format, utc) {
try {
var parser = makeParser(format);
var _parser2 = parser(input),
year = _parser2.year,
month = _parser2.month,
day = _parser2.day,
hours = _parser2.hours,
minutes = _parser2.minutes,
seconds = _parser2.seconds,
milliseconds = _parser2.milliseconds,
zone = _parser2.zone;
if (zone) {
return new Date(Date.UTC(year, month - 1, day, hours || 0, minutes || 0, seconds || 0, milliseconds || 0) + zone.offset * 60 * 1000);
}
var now = new Date();
var d = day || (!year && !month ? now.getDate() : 1);
var y = year || now.getFullYear();
var M = month > 0 ? month - 1 : now.getMonth();
var h = hours || 0;
var m = minutes || 0;
var s = seconds || 0;
var ms = milliseconds || 0;
if (utc) {
return new Date(Date.UTC(y, M, d, h, m, s, ms));
}
return new Date(y, M, d, h, m, s, ms);
} catch (e) {
return new Date(''); // Invalid Date
}
};
export default (function (o, C, d) {
var proto = C.prototype;
var oldParse = proto.parse;
proto.parse = function (cfg) {
var date = cfg.date,
format = cfg.format,
pl = cfg.pl,
utc = cfg.utc;
this.$u = utc;
if (format) {
locale = pl ? d.Ls[pl] : this.$locale();
this.$d = parseFormattedInput(date, format, utc);
this.init(cfg);
if (pl) this.$L = pl;
} else {
oldParse.call(this, cfg);
}
};
});
+8
View File
@@ -0,0 +1,8 @@
export default (function (o, c) {
var proto = c.prototype;
proto.dayOfYear = function (input) {
var dayOfYear = Math.round((this.startOf('day') - this.startOf('year')) / 864e5) + 1;
return input == null ? dayOfYear : this.add(input - dayOfYear, 'day');
};
});
+10
View File
@@ -0,0 +1,10 @@
export default (function (o, c, d) {
c.prototype.isBetween = function (a, b, u, i) {
var dA = d(a);
var dB = d(b);
i = i || '()';
var dAi = i[0] === '(';
var dBi = i[1] === ')';
return (dAi ? this.isAfter(dA, u) : !this.isBefore(dA, u)) && (dBi ? this.isBefore(dB, u) : !this.isAfter(dB, u)) || (dAi ? this.isBefore(dA, u) : !this.isAfter(dA, u)) && (dBi ? this.isAfter(dB, u) : !this.isBefore(dB, u));
};
});
+7
View File
@@ -0,0 +1,7 @@
export default (function (o, c) {
var proto = c.prototype;
proto.isLeapYear = function () {
return this.$y % 4 === 0 && this.$y % 100 !== 0 || this.$y % 400 === 0;
};
});
+5
View File
@@ -0,0 +1,5 @@
export default (function (o, c, f) {
f.isMoment = function (input) {
return f.isDayjs(input);
};
});
+5
View File
@@ -0,0 +1,5 @@
export default (function (o, c) {
c.prototype.isSameOrAfter = function (that, units) {
return this.isSame(that, units) || this.isAfter(that, units);
};
});
+5
View File
@@ -0,0 +1,5 @@
export default (function (o, c) {
c.prototype.isSameOrBefore = function (that, units) {
return this.isSame(that, units) || this.isBefore(that, units);
};
});
+57
View File
@@ -0,0 +1,57 @@
import { D, W, Y } from '../../constant';
var isoWeekPrettyUnit = 'isoweek';
export default (function (o, c, d) {
var getYearFirstThursday = function getYearFirstThursday(year) {
var yearFirstDay = d().year(year).startOf(Y);
var addDiffDays = 4 - yearFirstDay.isoWeekday();
if (yearFirstDay.isoWeekday() > 4) {
addDiffDays += 7;
}
return yearFirstDay.add(addDiffDays, D);
};
var getCurrentWeekThursday = function getCurrentWeekThursday(ins) {
return ins.add(4 - ins.isoWeekday(), D);
};
var proto = c.prototype;
proto.isoWeekYear = function () {
var nowWeekThursday = getCurrentWeekThursday(this);
return nowWeekThursday.year();
};
proto.isoWeek = function (week) {
if (!this.$utils().u(week)) {
return this.add((week - this.isoWeek()) * 7, D);
}
var nowWeekThursday = getCurrentWeekThursday(this);
var diffWeekThursday = getYearFirstThursday(this.isoWeekYear());
return nowWeekThursday.diff(diffWeekThursday, W) + 1;
};
proto.isoWeekday = function (week) {
if (!this.$utils().u(week)) {
return this.day(this.day() % 7 ? week : week - 7);
}
return this.day() || 7;
};
var oldStartOf = proto.startOf;
proto.startOf = function (units, startOf) {
var utils = this.$utils();
var isStartOf = !utils.u(startOf) ? startOf : true;
var unit = utils.p(units);
if (unit === isoWeekPrettyUnit) {
return isStartOf ? this.date(this.date() - (this.isoWeekday() - 1)).startOf('day') : this.date(this.date() - 1 - (this.isoWeekday() - 1) + 7).endOf('day');
}
return oldStartOf.bind(this)(units, startOf);
};
});
+15
View File
@@ -0,0 +1,15 @@
export default (function (o, c) {
var proto = c.prototype;
proto.isoWeeksInYear = function () {
var isLeapYear = this.isLeapYear();
var last = this.endOf('y');
var day = last.day();
if (day === 4 || isLeapYear && day === 5) {
return 53;
}
return 52;
};
});
+93
View File
@@ -0,0 +1,93 @@
export default (function (o, c, dayjs) {
// locale needed later
var proto = c.prototype;
var getShort = function getShort(ins, target, full, num) {
var locale = ins.name ? ins : ins.$locale();
if (!locale[target]) {
return locale[full].map(function (f) {
return f.substr(0, num);
});
}
return locale[target];
};
var getDayjsLocaleObject = function getDayjsLocaleObject() {
return dayjs.Ls[dayjs.locale()];
};
var localeData = function localeData() {
var _this = this;
return {
months: function months(instance) {
return instance ? instance.format('MMMM') : getShort(_this, 'months');
},
monthsShort: function monthsShort(instance) {
return instance ? instance.format('MMM') : getShort(_this, 'monthsShort', 'months', 3);
},
firstDayOfWeek: function firstDayOfWeek() {
return _this.$locale().weekStart || 0;
},
weekdaysMin: function weekdaysMin(instance) {
return instance ? instance.format('dd') : getShort(_this, 'weekdaysMin', 'weekdays', 2);
},
weekdaysShort: function weekdaysShort(instance) {
return instance ? instance.format('ddd') : getShort(_this, 'weekdaysShort', 'weekdays', 3);
},
longDateFormat: function longDateFormat(format) {
return _this.$locale().formats[format];
}
};
};
proto.localeData = function () {
return localeData.bind(this)();
};
dayjs.localeData = function () {
var localeObject = getDayjsLocaleObject();
return {
firstDayOfWeek: function firstDayOfWeek() {
return localeObject.weekStart || 0;
},
weekdays: function weekdays() {
return dayjs.weekdays();
},
weekdaysShort: function weekdaysShort() {
return dayjs.weekdaysShort();
},
weekdaysMin: function weekdaysMin() {
return dayjs.weekdaysMin();
},
months: function months() {
return dayjs.months();
},
monthsShort: function monthsShort() {
return dayjs.monthsShort();
}
};
};
dayjs.months = function () {
return getDayjsLocaleObject().months;
};
dayjs.monthsShort = function () {
return getShort(getDayjsLocaleObject(), 'monthsShort', 'months', 3);
};
dayjs.weekdays = function () {
return getDayjsLocaleObject().weekdays;
};
dayjs.weekdaysShort = function () {
return getShort(getDayjsLocaleObject(), 'weekdaysShort', 'weekdays', 3);
};
dayjs.weekdaysMin = function () {
return getShort(getDayjsLocaleObject(), 'weekdaysMin', 'weekdays', 2);
};
});
+36
View File
@@ -0,0 +1,36 @@
import { FORMAT_DEFAULT } from '../../constant';
export default (function (o, c, d) {
var proto = c.prototype;
var oldFormat = proto.format;
var englishFormats = {
LTS: 'h:mm:ss A',
LT: 'h:mm A',
L: 'MM/DD/YYYY',
LL: 'MMMM D, YYYY',
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A'
};
d.en.formats = englishFormats;
var t = function t(format) {
return format.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, function (_, a, b) {
return a || b.slice(1);
});
};
proto.format = function (formatStr) {
if (formatStr === void 0) {
formatStr = FORMAT_DEFAULT;
}
var _this$$locale = this.$locale(),
_this$$locale$formats = _this$$locale.formats,
formats = _this$$locale$formats === void 0 ? {} : _this$$locale$formats;
var result = formatStr.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, function (_, a, b) {
var B = b && b.toUpperCase();
return a || formats[b] || englishFormats[b] || t(formats[B]);
});
return oldFormat.call(this, result);
};
});
+36
View File
@@ -0,0 +1,36 @@
export default (function (o, c, d) {
var sortBy = function sortBy(method, dates) {
if (!dates.length) {
return d();
}
if (dates.length === 1 && dates[0].length > 0) {
var _dates = dates;
dates = _dates[0];
}
var result;
var _dates2 = dates;
result = _dates2[0];
for (var i = 1; i < dates.length; i += 1) {
if (!dates[i].isValid() || dates[i][method](result)) {
result = dates[i];
}
}
return result;
};
d.max = function () {
var args = [].slice.call(arguments, 0); // eslint-disable-line prefer-rest-params
return sortBy('isAfter', args);
};
d.min = function () {
var args = [].slice.call(arguments, 0); // eslint-disable-line prefer-rest-params
return sortBy('isBefore', args);
};
});
+41
View File
@@ -0,0 +1,41 @@
import { Q, M, D } from '../../constant';
export default (function (o, c) {
var proto = c.prototype;
proto.quarter = function (quarter) {
if (!this.$utils().u(quarter)) {
return this.month(this.month() % 3 + (quarter - 1) * 3);
}
return Math.ceil((this.month() + 1) / 3);
};
var oldAdd = proto.add;
proto.add = function (number, units) {
number = Number(number); // eslint-disable-line no-param-reassign
var unit = this.$utils().p(units);
if (unit === Q) {
return this.add(number * 3, M);
}
return oldAdd.bind(this)(number, units);
};
var oldStartOf = proto.startOf;
proto.startOf = function (units, startOf) {
var utils = this.$utils();
var isStartOf = !utils.u(startOf) ? startOf : true;
var unit = utils.p(units);
if (unit === Q) {
var quarter = this.quarter() - 1;
return isStartOf ? this.month(quarter * 3).startOf(M).startOf(D) : this.month(quarter * 3 + 2).endOf(M).endOf(D);
}
return oldStartOf.bind(this)(units, startOf);
};
});
+114
View File
@@ -0,0 +1,114 @@
import * as C from '../../constant';
export default (function (o, c, d) {
var proto = c.prototype;
d.en.relativeTime = {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years'
};
var fromTo = function fromTo(input, withoutSuffix, instance, isFrom) {
var loc = instance.$locale().relativeTime;
var T = [{
l: 's',
r: 44,
d: C.S
}, {
l: 'm',
r: 89
}, {
l: 'mm',
r: 44,
d: C.MIN
}, {
l: 'h',
r: 89
}, {
l: 'hh',
r: 21,
d: C.H
}, {
l: 'd',
r: 35
}, {
l: 'dd',
r: 25,
d: C.D
}, {
l: 'M',
r: 45
}, {
l: 'MM',
r: 10,
d: C.M
}, {
l: 'y',
r: 17
}, {
l: 'yy',
d: C.Y
}];
var Tl = T.length;
var result;
var out;
var isFuture;
for (var i = 0; i < Tl; i += 1) {
var t = T[i];
if (t.d) {
result = isFrom ? d(input).diff(instance, t.d, true) : instance.diff(input, t.d, true);
}
var abs = Math.round(Math.abs(result));
isFuture = result > 0;
if (abs <= t.r || !t.r) {
if (abs === 1 && i > 0) t = T[i - 1]; // 1 minutes -> a minute
var format = loc[t.l];
if (typeof format === 'string') {
out = format.replace('%d', abs);
} else {
out = format(abs, withoutSuffix, t.l, isFuture);
}
break;
}
}
if (withoutSuffix) return out;
return (isFuture ? loc.future : loc.past).replace('%s', out);
};
proto.to = function (input, withoutSuffix) {
return fromTo(input, withoutSuffix, this, true);
};
proto.from = function (input, withoutSuffix) {
return fromTo(input, withoutSuffix, this);
};
var makeNow = function makeNow(thisDay) {
return thisDay.$u ? d.utc() : d();
};
proto.toNow = function (withoutSuffix) {
return this.to(makeNow(this), withoutSuffix);
};
proto.fromNow = function (withoutSuffix) {
return this.from(makeNow(this), withoutSuffix);
};
});
+7
View File
@@ -0,0 +1,7 @@
export default (function (o, c) {
var proto = c.prototype;
proto.toArray = function () {
return [this.$y, this.$M, this.$D, this.$H, this.$m, this.$s, this.$ms];
};
});
+15
View File
@@ -0,0 +1,15 @@
export default (function (o, c) {
var proto = c.prototype;
proto.toObject = function () {
return {
years: this.$y,
months: this.$M,
date: this.$D,
hours: this.$H,
minutes: this.$m,
seconds: this.$s,
milliseconds: this.$ms
};
};
});
+12
View File
@@ -0,0 +1,12 @@
export default (function (option, Dayjs, dayjs) {
dayjs.updateLocale = function (locale, customConfig) {
var localeList = dayjs.Ls;
var localeConfig = localeList[locale];
if (!localeConfig) return;
var customConfigKeys = customConfig ? Object.keys(customConfig) : [];
customConfigKeys.forEach(function (c) {
localeConfig[c] = customConfig[c];
});
return localeConfig; // eslint-disable-line consistent-return
};
});
+116
View File
@@ -0,0 +1,116 @@
import { MILLISECONDS_A_MINUTE, MIN } from '../../constant';
export default (function (option, Dayjs, dayjs) {
var localOffset = new Date().getTimezoneOffset();
var proto = Dayjs.prototype;
dayjs.utc = function (date, format) {
var cfg = {
date: date,
utc: true,
format: format
};
return new Dayjs(cfg); // eslint-disable-line no-use-before-define
};
proto.utc = function () {
return dayjs(this.toDate(), {
locale: this.$L,
utc: true
});
};
proto.local = function () {
return dayjs(this.toDate(), {
locale: this.$L,
utc: false
});
};
var oldParse = proto.parse;
proto.parse = function (cfg) {
if (cfg.utc) {
this.$u = true;
}
if (!this.$utils().u(cfg.$offset)) {
this.$offset = cfg.$offset;
}
oldParse.call(this, cfg);
};
var oldInit = proto.init;
proto.init = function () {
if (this.$u) {
var $d = this.$d;
this.$y = $d.getUTCFullYear();
this.$M = $d.getUTCMonth();
this.$D = $d.getUTCDate();
this.$W = $d.getUTCDay();
this.$H = $d.getUTCHours();
this.$m = $d.getUTCMinutes();
this.$s = $d.getUTCSeconds();
this.$ms = $d.getUTCMilliseconds();
} else {
oldInit.call(this);
}
};
var oldUtcOffset = proto.utcOffset;
proto.utcOffset = function (input) {
var _this$$utils = this.$utils(),
u = _this$$utils.u;
if (u(input)) {
if (this.$u) {
return 0;
}
if (!u(this.$offset)) {
return this.$offset;
}
return oldUtcOffset.call(this);
}
var offset = Math.abs(input) <= 16 ? input * 60 : input;
var ins;
if (input !== 0) {
ins = this.local().add(offset + localOffset, MIN);
ins.$offset = offset;
} else {
ins = this.utc();
}
return ins;
};
var oldFormat = proto.format;
var UTC_FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ss[Z]';
proto.format = function (formatStr) {
var str = formatStr || (this.$u ? UTC_FORMAT_DEFAULT : '');
return oldFormat.call(this, str);
};
proto.valueOf = function () {
var addedOffset = !this.$utils().u(this.$offset) ? this.$offset + localOffset : 0;
return this.$d.valueOf() - addedOffset * MILLISECONDS_A_MINUTE;
};
proto.isUTC = function () {
return !!this.$u;
};
proto.toISOString = function () {
return this.toDate().toISOString();
};
proto.toString = function () {
return this.toDate().toUTCString();
};
});
+43
View File
@@ -0,0 +1,43 @@
import { MS, Y, D, W } from '../../constant';
export default (function (o, c) {
var proto = c.prototype;
proto.week = function (week) {
if (week === void 0) {
week = null;
}
if (week !== null) {
return this.add((week - this.week()) * 7, D);
}
var yearStart = this.$locale().yearStart || 1;
if (this.month() === 11 && this.date() > 25) {
var nextYearStartDay = this.startOf(Y).add(1, Y).date(yearStart);
var thisEndOfWeek = this.endOf(W);
if (nextYearStartDay.isBefore(thisEndOfWeek)) {
return 1;
}
}
var yearStartDay = this.startOf(Y).date(yearStart);
var yearStartWeek = yearStartDay.startOf(W).subtract(1, MS);
var diffInWeek = this.diff(yearStartWeek, W, true);
if (diffInWeek < 0) {
return this.startOf('week').week();
}
return Math.ceil(diffInWeek);
};
proto.weeks = function (week) {
if (week === void 0) {
week = null;
}
return this.week(week);
};
});
+15
View File
@@ -0,0 +1,15 @@
export default (function (o, c) {
var proto = c.prototype;
proto.weekYear = function () {
var month = this.month();
var weekOfYear = this.week();
var year = this.year();
if (weekOfYear === 1 && month === 11) {
return year + 1;
}
return year;
};
});
+15
View File
@@ -0,0 +1,15 @@
export default (function (o, c) {
var proto = c.prototype;
proto.weekday = function (input) {
var weekStart = this.$locale().weekStart || 0;
var $W = this.$W;
var weekday = ($W < weekStart ? $W + 7 : $W) - weekStart;
if (this.$utils().u(input)) {
return weekday;
}
return this.subtract(weekday, 'day').add(input, 'day');
};
});