ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
732 lines (726 loc) • 19.3 kB
JavaScript
import { __read } from 'tslib';
import addMonths from 'date-fns/addMonths';
import addYears from 'date-fns/addYears';
import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
import differenceInCalendarMonths from 'date-fns/differenceInCalendarMonths';
import differenceInCalendarYears from 'date-fns/differenceInCalendarYears';
import differenceInHours from 'date-fns/differenceInHours';
import differenceInMinutes from 'date-fns/differenceInMinutes';
import differenceInSeconds from 'date-fns/differenceInSeconds';
import isFirstDayOfMonth from 'date-fns/isFirstDayOfMonth';
import isLastDayOfMonth from 'date-fns/isLastDayOfMonth';
import isSameDay from 'date-fns/isSameDay';
import isSameHour from 'date-fns/isSameHour';
import isSameMinute from 'date-fns/isSameMinute';
import isSameMonth from 'date-fns/isSameMonth';
import isSameSecond from 'date-fns/isSameSecond';
import isSameYear from 'date-fns/isSameYear';
import isToday from 'date-fns/isToday';
import isValid from 'date-fns/isValid';
import setDay from 'date-fns/setDay';
import setMonth from 'date-fns/setMonth';
import setYear from 'date-fns/setYear';
import startOfMonth from 'date-fns/startOfMonth';
import startOfWeek from 'date-fns/startOfWeek';
import { warn } from 'ng-zorro-antd/core/logger';
/**
* @fileoverview added by tsickle
* Generated from: candy-date.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @param {?} rangeValue
* @return {?}
*/
function sortRangeValue(rangeValue) {
if (Array.isArray(rangeValue)) {
var _a = __read(rangeValue, 2), start = _a[0], end = _a[1];
return start && end && start.isAfterSecond(end) ? [end, start] : [start, end];
}
return rangeValue;
}
/**
* @param {?} value
* @return {?}
*/
function normalizeRangeValue(value) {
var _a = __read(value || [], 2), start = _a[0], end = _a[1];
/** @type {?} */
var newStart = start || new CandyDate();
/** @type {?} */
var newEnd = (end === null || end === void 0 ? void 0 : end.isSameMonth(newStart)) ? end.addMonths(1) : end || newStart.addMonths(1);
return [newStart, newEnd];
}
/**
* @param {?} value
* @return {?}
*/
function cloneDate(value) {
if (Array.isArray(value)) {
return value.map((/**
* @param {?} v
* @return {?}
*/
function (v) { return (v instanceof CandyDate ? v.clone() : null); }));
}
else {
return value instanceof CandyDate ? value.clone() : null;
}
}
/**
* Wrapping kind APIs for date operating and unify
* NOTE: every new API return new CandyDate object without side effects to the former Date object
* NOTE: most APIs are based on local time other than customized locale id (this needs tobe support in future)
* TODO: support format() against to angular's core API
*/
var /**
* Wrapping kind APIs for date operating and unify
* NOTE: every new API return new CandyDate object without side effects to the former Date object
* NOTE: most APIs are based on local time other than customized locale id (this needs tobe support in future)
* TODO: support format() against to angular's core API
*/
CandyDate = /** @class */ (function () {
// locale: string; // Custom specified locale ID
function CandyDate(date) {
if (date) {
if (date instanceof Date) {
this.nativeDate = date;
}
else if (typeof date === 'string' || typeof date === 'number') {
warn('The string type is not recommended for date-picker, use "Date" type');
this.nativeDate = new Date(date);
}
else {
throw new Error('The input date type is not supported ("Date" is now recommended)');
}
}
else {
this.nativeDate = new Date();
}
}
// getLocale(): string {
// return this.locale;
// }
// setLocale(locale: string): CandyDate {
// this.locale = locale;
// return this;
// }
// getLocale(): string {
// return this.locale;
// }
// setLocale(locale: string): CandyDate {
// this.locale = locale;
// return this;
// }
/**
* @param {?=} options
* @return {?}
*/
CandyDate.prototype.calendarStart =
// getLocale(): string {
// return this.locale;
// }
// setLocale(locale: string): CandyDate {
// this.locale = locale;
// return this;
// }
/**
* @param {?=} options
* @return {?}
*/
function (options) {
return new CandyDate(startOfWeek(startOfMonth(this.nativeDate), options));
};
// ---------------------------------------------------------------------
// | Native shortcuts
// -----------------------------------------------------------------------------\
// ---------------------------------------------------------------------
// | Native shortcuts
// -----------------------------------------------------------------------------\
/**
* @return {?}
*/
CandyDate.prototype.getYear =
// ---------------------------------------------------------------------
// | Native shortcuts
// -----------------------------------------------------------------------------\
/**
* @return {?}
*/
function () {
return this.nativeDate.getFullYear();
};
/**
* @return {?}
*/
CandyDate.prototype.getMonth = /**
* @return {?}
*/
function () {
return this.nativeDate.getMonth();
};
/**
* @return {?}
*/
CandyDate.prototype.getDay = /**
* @return {?}
*/
function () {
return this.nativeDate.getDay();
};
/**
* @return {?}
*/
CandyDate.prototype.getTime = /**
* @return {?}
*/
function () {
return this.nativeDate.getTime();
};
/**
* @return {?}
*/
CandyDate.prototype.getDate = /**
* @return {?}
*/
function () {
return this.nativeDate.getDate();
};
/**
* @return {?}
*/
CandyDate.prototype.getHours = /**
* @return {?}
*/
function () {
return this.nativeDate.getHours();
};
/**
* @return {?}
*/
CandyDate.prototype.getMinutes = /**
* @return {?}
*/
function () {
return this.nativeDate.getMinutes();
};
/**
* @return {?}
*/
CandyDate.prototype.getSeconds = /**
* @return {?}
*/
function () {
return this.nativeDate.getSeconds();
};
/**
* @return {?}
*/
CandyDate.prototype.getMilliseconds = /**
* @return {?}
*/
function () {
return this.nativeDate.getMilliseconds();
};
// ---------------------------------------------------------------------
// | New implementing APIs
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// | New implementing APIs
// ---------------------------------------------------------------------
/**
* @return {?}
*/
CandyDate.prototype.clone =
// ---------------------------------------------------------------------
// | New implementing APIs
// ---------------------------------------------------------------------
/**
* @return {?}
*/
function () {
return new CandyDate(new Date(this.nativeDate));
};
/**
* @param {?} hour
* @param {?} minute
* @param {?} second
* @return {?}
*/
CandyDate.prototype.setHms = /**
* @param {?} hour
* @param {?} minute
* @param {?} second
* @return {?}
*/
function (hour, minute, second) {
return new CandyDate(this.nativeDate.setHours(hour, minute, second));
};
/**
* @param {?} year
* @return {?}
*/
CandyDate.prototype.setYear = /**
* @param {?} year
* @return {?}
*/
function (year) {
return new CandyDate(setYear(this.nativeDate, year));
};
/**
* @param {?} amount
* @return {?}
*/
CandyDate.prototype.addYears = /**
* @param {?} amount
* @return {?}
*/
function (amount) {
return new CandyDate(addYears(this.nativeDate, amount));
};
// NOTE: month starts from 0
// NOTE: Don't use the native API for month manipulation as it not restrict the date when it overflows, eg. (new Date('2018-7-31')).setMonth(1) will be date of 2018-3-03 instead of 2018-2-28
// NOTE: month starts from 0
// NOTE: Don't use the native API for month manipulation as it not restrict the date when it overflows, eg. (new Date('2018-7-31')).setMonth(1) will be date of 2018-3-03 instead of 2018-2-28
/**
* @param {?} month
* @return {?}
*/
CandyDate.prototype.setMonth =
// NOTE: month starts from 0
// NOTE: Don't use the native API for month manipulation as it not restrict the date when it overflows, eg. (new Date('2018-7-31')).setMonth(1) will be date of 2018-3-03 instead of 2018-2-28
/**
* @param {?} month
* @return {?}
*/
function (month) {
return new CandyDate(setMonth(this.nativeDate, month));
};
/**
* @param {?} amount
* @return {?}
*/
CandyDate.prototype.addMonths = /**
* @param {?} amount
* @return {?}
*/
function (amount) {
return new CandyDate(addMonths(this.nativeDate, amount));
};
/**
* @param {?} day
* @param {?=} options
* @return {?}
*/
CandyDate.prototype.setDay = /**
* @param {?} day
* @param {?=} options
* @return {?}
*/
function (day, options) {
return new CandyDate(setDay(this.nativeDate, day, options));
};
/**
* @param {?} amount
* @return {?}
*/
CandyDate.prototype.setDate = /**
* @param {?} amount
* @return {?}
*/
function (amount) {
/** @type {?} */
var date = new Date(this.nativeDate);
date.setDate(amount);
return new CandyDate(date);
};
/**
* @param {?} amount
* @return {?}
*/
CandyDate.prototype.addDays = /**
* @param {?} amount
* @return {?}
*/
function (amount) {
return this.setDate(this.getDate() + amount);
};
/**
* @param {?} date
* @param {?=} grain
* @return {?}
*/
CandyDate.prototype.isSame = /**
* @param {?} date
* @param {?=} grain
* @return {?}
*/
function (date, grain) {
if (grain === void 0) { grain = 'day'; }
/** @type {?} */
var fn;
switch (grain) {
case 'year':
fn = isSameYear;
break;
case 'month':
fn = isSameMonth;
break;
case 'day':
fn = isSameDay;
break;
case 'hour':
fn = isSameHour;
break;
case 'minute':
fn = isSameMinute;
break;
case 'second':
fn = isSameSecond;
break;
default:
fn = isSameDay;
break;
}
return fn(this.nativeDate, this.toNativeDate(date));
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isSameYear = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.isSame(date, 'year');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isSameMonth = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.isSame(date, 'month');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isSameDay = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.isSame(date, 'day');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isSameHour = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.isSame(date, 'hour');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isSameMinute = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.isSame(date, 'minute');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isSameSecond = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.isSame(date, 'second');
};
/**
* @param {?} date
* @param {?=} grain
* @param {?=} isBefore
* @return {?}
*/
CandyDate.prototype.compare = /**
* @param {?} date
* @param {?=} grain
* @param {?=} isBefore
* @return {?}
*/
function (date, grain, isBefore) {
if (grain === void 0) { grain = 'day'; }
if (isBefore === void 0) { isBefore = true; }
if (date === null) {
return false;
}
/** @type {?} */
var fn;
switch (grain) {
case 'year':
fn = differenceInCalendarYears;
break;
case 'month':
fn = differenceInCalendarMonths;
break;
case 'day':
fn = differenceInCalendarDays;
break;
case 'hour':
fn = differenceInHours;
break;
case 'minute':
fn = differenceInMinutes;
break;
case 'second':
fn = differenceInSeconds;
break;
default:
fn = differenceInCalendarDays;
break;
}
return isBefore ? fn(this.nativeDate, this.toNativeDate(date)) < 0 : fn(this.nativeDate, this.toNativeDate(date)) > 0;
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isBeforeYear = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'year');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isBeforeMonth = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'month');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isBeforeDay = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'day');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isBeforeHour = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'hour');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isBeforeMinute = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'minute');
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isBeforeSecond = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'second');
};
// TODO: isBefore
// TODO: isBefore
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isAfterYear =
// TODO: isBefore
/**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'year', false);
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isAfterMonth = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'month', false);
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isAfterDay = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'day', false);
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isAfterHour = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'hour', false);
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isAfterMinute = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'minute', false);
};
/**
* @param {?} date
* @return {?}
*/
CandyDate.prototype.isAfterSecond = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.compare(date, 'second', false);
};
// Equal to today accurate to "day"
// Equal to today accurate to "day"
/**
* @return {?}
*/
CandyDate.prototype.isToday =
// Equal to today accurate to "day"
/**
* @return {?}
*/
function () {
return isToday(this.nativeDate);
};
/**
* @return {?}
*/
CandyDate.prototype.isValid = /**
* @return {?}
*/
function () {
return isValid(this.nativeDate);
};
/**
* @return {?}
*/
CandyDate.prototype.isFirstDayOfMonth = /**
* @return {?}
*/
function () {
return isFirstDayOfMonth(this.nativeDate);
};
/**
* @return {?}
*/
CandyDate.prototype.isLastDayOfMonth = /**
* @return {?}
*/
function () {
return isLastDayOfMonth(this.nativeDate);
};
/**
* @private
* @param {?} date
* @return {?}
*/
CandyDate.prototype.toNativeDate = /**
* @private
* @param {?} date
* @return {?}
*/
function (date) {
return date instanceof CandyDate ? date.nativeDate : date;
};
return CandyDate;
}());
if (false) {
/** @type {?} */
CandyDate.prototype.nativeDate;
}
/**
* @fileoverview added by tsickle
* Generated from: time.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @license
* Copyright Alibaba.com All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
/** @type {?} */
var timeUnits = [
['Y', 1000 * 60 * 60 * 24 * 365],
['M', 1000 * 60 * 60 * 24 * 30],
['D', 1000 * 60 * 60 * 24],
['H', 1000 * 60 * 60],
['m', 1000 * 60],
['s', 1000],
['S', 1] // million seconds
];
/**
* @fileoverview added by tsickle
* Generated from: public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: ng-zorro-antd-core-time.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { CandyDate, cloneDate, normalizeRangeValue, sortRangeValue, timeUnits };
//# sourceMappingURL=ng-zorro-antd-core-time.js.map