esday 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EsDay-KXQgnL1r.d.ts +89 -0
- package/README.md +33 -0
- package/chunk-MLKGABMK.js +7 -0
- package/chunk-NUV73YDM.js +60 -0
- package/chunk-SQBPUYUY.js +140 -0
- package/index.d.ts +2 -2
- package/index.js +136 -173
- package/locales/en.d.ts +6 -0
- package/locales/en.js +1 -0
- package/locales/zh.d.ts +6 -0
- package/locales/zh.js +64 -0
- package/package.json +37 -5
- package/plugins/customParseFormat/index.d.ts +1 -1
- package/plugins/customParseFormat/index.js +7 -7
- package/plugins/isToday/index.d.ts +1 -1
- package/plugins/locale/index.d.ts +75 -0
- package/plugins/locale/index.js +70 -0
- package/plugins/utc/index.d.ts +22 -0
- package/plugins/utc/index.js +40 -0
- package/EsDay-CKy0jEj2.d.ts +0 -68
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
declare const UNIT_MAP: {
|
|
2
|
+
readonly y: "year";
|
|
3
|
+
readonly M: "month";
|
|
4
|
+
readonly D: "date";
|
|
5
|
+
readonly d: "day";
|
|
6
|
+
readonly h: "hour";
|
|
7
|
+
readonly m: "minute";
|
|
8
|
+
readonly s: "second";
|
|
9
|
+
readonly ms: "millisecond";
|
|
10
|
+
readonly w: "week";
|
|
11
|
+
};
|
|
12
|
+
type ShortUnit = keyof typeof UNIT_MAP;
|
|
13
|
+
type PrettyUnitType = typeof UNIT_MAP[ShortUnit];
|
|
14
|
+
type UnitType = ShortUnit | PrettyUnitType;
|
|
15
|
+
type PrettyUnit<T extends UnitType> = T extends ShortUnit ? typeof UNIT_MAP[T] : T;
|
|
16
|
+
type UnionUnit<T extends ShortUnit> = T | PrettyUnit<T>;
|
|
17
|
+
type UnitYear = UnionUnit<'y'>;
|
|
18
|
+
type UnitMonth = UnionUnit<'M'>;
|
|
19
|
+
type UnitDate = UnionUnit<'D'>;
|
|
20
|
+
type UnitDay = UnionUnit<'d'>;
|
|
21
|
+
type UnitHour = UnionUnit<'h'>;
|
|
22
|
+
type UnitMin = UnionUnit<'m'>;
|
|
23
|
+
type UnitSecond = UnionUnit<'s'>;
|
|
24
|
+
type UnitMs = UnionUnit<'ms'>;
|
|
25
|
+
type UnitWeek = UnionUnit<'w'>;
|
|
26
|
+
|
|
27
|
+
type SimpleType = string | number | boolean | null | undefined;
|
|
28
|
+
type SimpleObject = Record<string, SimpleType>;
|
|
29
|
+
|
|
30
|
+
type EsDayFactoryParserFn = (d?: DateType, ...others: (SimpleType | {
|
|
31
|
+
[key: string]: SimpleType;
|
|
32
|
+
})[]) => EsDay;
|
|
33
|
+
interface EsDayFactory {
|
|
34
|
+
(...args: Parameters<EsDayFactoryParserFn>): ReturnType<EsDayFactoryParserFn>;
|
|
35
|
+
extend: <T extends {}>(plugin: EsDayPlugin<T>, option?: T) => EsDayFactory;
|
|
36
|
+
}
|
|
37
|
+
type EsDayPlugin<T extends {}> = (option: T, dayTsClass: typeof EsDay, esday: EsDayFactory) => void;
|
|
38
|
+
type DateType = EsDay | Date | string | number | number[] | null | undefined | object;
|
|
39
|
+
|
|
40
|
+
declare interface EsDay {
|
|
41
|
+
year: (() => number) & ((year: number, month?: number, date?: number) => EsDay);
|
|
42
|
+
month: (() => number) & ((month: number, date?: number) => EsDay);
|
|
43
|
+
date: (() => number) & ((date: number) => EsDay);
|
|
44
|
+
day: (() => number) & ((day: number) => EsDay);
|
|
45
|
+
hour: (() => number) & ((hours: number, min?: number, sec?: number, ms?: number) => EsDay);
|
|
46
|
+
minute: (() => number) & ((min: number, sec?: number, ms?: number) => EsDay);
|
|
47
|
+
second: (() => number) & ((sec: number, ms?: number) => EsDay);
|
|
48
|
+
millisecond: (() => number) & ((ms: number) => EsDay);
|
|
49
|
+
}
|
|
50
|
+
declare class EsDay {
|
|
51
|
+
private $d;
|
|
52
|
+
/**
|
|
53
|
+
* mainly for plugin compatibility
|
|
54
|
+
* store data such as locale name, utc mode, etc.
|
|
55
|
+
*/
|
|
56
|
+
private $conf;
|
|
57
|
+
constructor(d: Exclude<DateType, EsDay>, conf?: SimpleObject);
|
|
58
|
+
private parse;
|
|
59
|
+
private $parseDate;
|
|
60
|
+
isSame(that: DateType, units?: UnitType): boolean;
|
|
61
|
+
isAfter(that: DateType, units?: UnitType): boolean;
|
|
62
|
+
isBefore(that: DateType, units?: UnitType): boolean;
|
|
63
|
+
valueOf(): number;
|
|
64
|
+
unix(): number;
|
|
65
|
+
isValid(): boolean;
|
|
66
|
+
clone(): EsDay;
|
|
67
|
+
format(formatStr?: string): string;
|
|
68
|
+
utcOffset(): number;
|
|
69
|
+
startOf(units: UnitType): EsDay;
|
|
70
|
+
endOf(units: UnitType): EsDay;
|
|
71
|
+
add(number: number, units: UnitType): EsDay;
|
|
72
|
+
subtract(number: number, units: UnitType): EsDay;
|
|
73
|
+
get(units: Exclude<UnitType, UnitWeek>): number;
|
|
74
|
+
set(unit: UnitYear, year: number, month?: number, date?: number): EsDay;
|
|
75
|
+
set(unit: UnitMonth, month: number, date?: number): EsDay;
|
|
76
|
+
set(unit: UnitDate, date: number): EsDay;
|
|
77
|
+
set(unit: UnitDay, day: number): EsDay;
|
|
78
|
+
set(unit: UnitHour, hours: number, min?: number, sec?: number, ms?: number): EsDay;
|
|
79
|
+
set(unit: UnitMin, min: number, sec?: number, ms?: number): EsDay;
|
|
80
|
+
set(unit: UnitSecond, sec: number, ms?: number): EsDay;
|
|
81
|
+
set(unit: UnitMs, ms: number): EsDay;
|
|
82
|
+
toDate(): Date;
|
|
83
|
+
toJSON(): string | null;
|
|
84
|
+
toISOString(): string;
|
|
85
|
+
toString(): string;
|
|
86
|
+
private $set;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { type DateType as D, type EsDayFactory as E, type PrettyUnit as P, type UnitType as U, EsDay as a, type PrettyUnitType as b, type EsDayFactoryParserFn as c, type EsDayPlugin as d };
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
## esday
|
|
2
|
+
|
|
3
|
+
 [](https://makeapullrequest.com)
|
|
4
|
+
|
|
5
|
+
> 🚧 working in progress
|
|
6
|
+
|
|
7
|
+
> esday is a JavaScript library inspired by [Day.js](https://github.com/iamkun/dayjs), esday has a largely similar API to Day.js (v1.11.13), but it is written in TypeScript and fully supports es modules.
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
import { esday } from 'esday'
|
|
11
|
+
import { isTodayPlugin } from 'esday/plugins/isToday'
|
|
12
|
+
|
|
13
|
+
esday.extend(isTodayPlugin)
|
|
14
|
+
|
|
15
|
+
esday('2024-12-10').set('year', 2025).add(1, 'month').isToday()
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Concepts
|
|
19
|
+
|
|
20
|
+
- **Modern API**: Provides the same API as Day.js, with some features moved to plugins for a simpler core.
|
|
21
|
+
- **Immutable**: esday is immutable, which means that all operations will return a new instance of esday.
|
|
22
|
+
|
|
23
|
+
## Differences with Day.js
|
|
24
|
+
|
|
25
|
+
- **locale**: esday core does not support locales, localizied formats are provided by plugins.
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
30
|
+
|
|
31
|
+
This project also partially contains code derived or copied from the following projects:
|
|
32
|
+
|
|
33
|
+
- [Day.js](https://github.com/iamkun/dayjs)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/locales/en.ts
|
|
2
|
+
var localeEn = {
|
|
3
|
+
name: "en",
|
|
4
|
+
weekdays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
|
5
|
+
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
|
6
|
+
weekdaysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
7
|
+
weekdaysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
|
|
8
|
+
monthsShort: [
|
|
9
|
+
"Jan",
|
|
10
|
+
"Feb",
|
|
11
|
+
"Mar",
|
|
12
|
+
"Apr",
|
|
13
|
+
"May",
|
|
14
|
+
"Jun",
|
|
15
|
+
"Jul",
|
|
16
|
+
"Aug",
|
|
17
|
+
"Sep",
|
|
18
|
+
"Oct",
|
|
19
|
+
"Nov",
|
|
20
|
+
"Dec"
|
|
21
|
+
],
|
|
22
|
+
weekStart: 1,
|
|
23
|
+
yearStart: 4,
|
|
24
|
+
formats: {
|
|
25
|
+
LT: "HH:mm",
|
|
26
|
+
LTS: "HH:mm:ss",
|
|
27
|
+
L: "DD/MM/YYYY",
|
|
28
|
+
LL: "D MMMM YYYY",
|
|
29
|
+
LLL: "D MMMM YYYY HH:mm",
|
|
30
|
+
LLLL: "dddd, D MMMM YYYY HH:mm"
|
|
31
|
+
},
|
|
32
|
+
relativeTime: {
|
|
33
|
+
future: "in %s",
|
|
34
|
+
past: "%s ago",
|
|
35
|
+
s: "a few seconds",
|
|
36
|
+
m: "a minute",
|
|
37
|
+
mm: "%d minutes",
|
|
38
|
+
h: "an hour",
|
|
39
|
+
hh: "%d hours",
|
|
40
|
+
d: "a day",
|
|
41
|
+
dd: "%d days",
|
|
42
|
+
M: "a month",
|
|
43
|
+
MM: "%d months",
|
|
44
|
+
y: "a year",
|
|
45
|
+
yy: "%d years"
|
|
46
|
+
},
|
|
47
|
+
meridiem: (hour, minute, isLowercase) => {
|
|
48
|
+
const m = hour < 12 ? "AM" : "PM";
|
|
49
|
+
return isLowercase ? m.toLowerCase() : m;
|
|
50
|
+
},
|
|
51
|
+
ordinal: (n) => {
|
|
52
|
+
const s = ["th", "st", "nd", "rd"];
|
|
53
|
+
const v = n % 100;
|
|
54
|
+
return `[${n}${s[(v - 20) % 10] || s[v] || s[0]}]`;
|
|
55
|
+
},
|
|
56
|
+
invalidDate: "Invalid date"
|
|
57
|
+
};
|
|
58
|
+
var en_default = localeEn;
|
|
59
|
+
|
|
60
|
+
export { en_default };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
2
|
+
|
|
3
|
+
// src/common/constant.ts
|
|
4
|
+
var constant_exports = {};
|
|
5
|
+
__export(constant_exports, {
|
|
6
|
+
DATE: () => DATE,
|
|
7
|
+
DAY: () => DAY,
|
|
8
|
+
FORMAT_DEFAULT: () => FORMAT_DEFAULT,
|
|
9
|
+
HOUR: () => HOUR,
|
|
10
|
+
INDEX_MONDAY: () => INDEX_MONDAY,
|
|
11
|
+
INVALID_DATE_STRING: () => INVALID_DATE_STRING,
|
|
12
|
+
MILLISECONDS_A_DAY: () => MILLISECONDS_A_DAY,
|
|
13
|
+
MILLISECONDS_A_HOUR: () => MILLISECONDS_A_HOUR,
|
|
14
|
+
MILLISECONDS_A_MINUTE: () => MILLISECONDS_A_MINUTE,
|
|
15
|
+
MILLISECONDS_A_SECOND: () => MILLISECONDS_A_SECOND,
|
|
16
|
+
MILLISECONDS_A_WEEK: () => MILLISECONDS_A_WEEK,
|
|
17
|
+
MIN: () => MIN,
|
|
18
|
+
MONTH: () => MONTH,
|
|
19
|
+
MS: () => MS,
|
|
20
|
+
REGEX_FORMAT: () => REGEX_FORMAT,
|
|
21
|
+
REGEX_PARSE: () => REGEX_PARSE,
|
|
22
|
+
SECOND: () => SECOND,
|
|
23
|
+
SECONDS_A_DAY: () => SECONDS_A_DAY,
|
|
24
|
+
SECONDS_A_HOUR: () => SECONDS_A_HOUR,
|
|
25
|
+
SECONDS_A_MINUTE: () => SECONDS_A_MINUTE,
|
|
26
|
+
SECONDS_A_WEEK: () => SECONDS_A_WEEK,
|
|
27
|
+
WEEK: () => WEEK,
|
|
28
|
+
YEAR: () => YEAR
|
|
29
|
+
});
|
|
30
|
+
var SECONDS_A_MINUTE = 60;
|
|
31
|
+
var SECONDS_A_HOUR = SECONDS_A_MINUTE * 60;
|
|
32
|
+
var SECONDS_A_DAY = SECONDS_A_HOUR * 24;
|
|
33
|
+
var SECONDS_A_WEEK = SECONDS_A_DAY * 7;
|
|
34
|
+
var MILLISECONDS_A_SECOND = 1e3;
|
|
35
|
+
var MILLISECONDS_A_MINUTE = SECONDS_A_MINUTE * MILLISECONDS_A_SECOND;
|
|
36
|
+
var MILLISECONDS_A_HOUR = SECONDS_A_HOUR * MILLISECONDS_A_SECOND;
|
|
37
|
+
var MILLISECONDS_A_DAY = SECONDS_A_DAY * MILLISECONDS_A_SECOND;
|
|
38
|
+
var MILLISECONDS_A_WEEK = SECONDS_A_WEEK * MILLISECONDS_A_SECOND;
|
|
39
|
+
var INDEX_MONDAY = 1;
|
|
40
|
+
var MS = "millisecond";
|
|
41
|
+
var SECOND = "second";
|
|
42
|
+
var MIN = "minute";
|
|
43
|
+
var HOUR = "hour";
|
|
44
|
+
var DAY = "day";
|
|
45
|
+
var WEEK = "week";
|
|
46
|
+
var MONTH = "month";
|
|
47
|
+
var YEAR = "year";
|
|
48
|
+
var DATE = "date";
|
|
49
|
+
var FORMAT_DEFAULT = "YYYY-MM-DDTHH:mm:ssZ";
|
|
50
|
+
var INVALID_DATE_STRING = "Invalid Date";
|
|
51
|
+
var REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
|
|
52
|
+
var REGEX_FORMAT = /\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
|
|
53
|
+
|
|
54
|
+
// src/common/is.ts
|
|
55
|
+
function isUndefined(value) {
|
|
56
|
+
return value === void 0;
|
|
57
|
+
}
|
|
58
|
+
function undefinedOr(v, or) {
|
|
59
|
+
return isUndefined(v) ? or : v;
|
|
60
|
+
}
|
|
61
|
+
function isObject(value) {
|
|
62
|
+
return typeof value === "object" && value !== null;
|
|
63
|
+
}
|
|
64
|
+
function isEmptyObject(value) {
|
|
65
|
+
return isObject(value) && Object.keys(value).length === 0;
|
|
66
|
+
}
|
|
67
|
+
function isString(value) {
|
|
68
|
+
return typeof value === "string";
|
|
69
|
+
}
|
|
70
|
+
function isArray(value) {
|
|
71
|
+
return Array.isArray(value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/common/unit.ts
|
|
75
|
+
var UNIT_MAP = {
|
|
76
|
+
y: YEAR,
|
|
77
|
+
M: MONTH,
|
|
78
|
+
D: DATE,
|
|
79
|
+
d: DAY,
|
|
80
|
+
h: HOUR,
|
|
81
|
+
m: MIN,
|
|
82
|
+
s: SECOND,
|
|
83
|
+
ms: MS,
|
|
84
|
+
w: WEEK
|
|
85
|
+
};
|
|
86
|
+
function prettyUnit(u) {
|
|
87
|
+
const maybePrettyUnit = UNIT_MAP[u];
|
|
88
|
+
return maybePrettyUnit || u;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/common/date-fields.ts
|
|
92
|
+
var UNIT_FIELD_MAP = {
|
|
93
|
+
year: "FullYear",
|
|
94
|
+
month: "Month",
|
|
95
|
+
date: "Date",
|
|
96
|
+
day: "Day",
|
|
97
|
+
hour: "Hours",
|
|
98
|
+
minute: "Minutes",
|
|
99
|
+
second: "Seconds",
|
|
100
|
+
millisecond: "Milliseconds"
|
|
101
|
+
};
|
|
102
|
+
function unitToField(unit) {
|
|
103
|
+
const p = prettyUnit(unit);
|
|
104
|
+
return UNIT_FIELD_MAP[p];
|
|
105
|
+
}
|
|
106
|
+
function getUnitInDate(date, unit, utc) {
|
|
107
|
+
const field = unitToField(unit);
|
|
108
|
+
const method = `get${utc ? "UTC" : ""}${field}`;
|
|
109
|
+
return date[method]();
|
|
110
|
+
}
|
|
111
|
+
function setUnitInDate(date, unit, value, utc) {
|
|
112
|
+
const field = unitToField(unit);
|
|
113
|
+
const method = `set${utc ? "UTC" : ""}${field}`;
|
|
114
|
+
date[method](...isArray(value) ? value : [value]);
|
|
115
|
+
return date;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/common/esday-inst.ts
|
|
119
|
+
function createInstanceFromExist(d, existInst) {
|
|
120
|
+
const newInst = existInst.clone();
|
|
121
|
+
newInst["$d"] = d;
|
|
122
|
+
return newInst;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/common/str-utils.ts
|
|
126
|
+
function padStart(origin, length, pad) {
|
|
127
|
+
const originStr = String(origin);
|
|
128
|
+
if (!originStr || originStr.length >= length)
|
|
129
|
+
return originStr;
|
|
130
|
+
return `${Array.from({ length: length + 1 - originStr.length }).join(pad)}${originStr}`;
|
|
131
|
+
}
|
|
132
|
+
function padZoneStr(utcOffset) {
|
|
133
|
+
const negMinutes = -utcOffset;
|
|
134
|
+
const minutes = Math.abs(negMinutes);
|
|
135
|
+
const hourOffset = Math.floor(minutes / 60);
|
|
136
|
+
const minuteOffset = minutes % 60;
|
|
137
|
+
return `${negMinutes <= 0 ? "+" : "-"}${padStart(hourOffset, 2, "0")}:${padStart(minuteOffset, 2, "0")}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export { constant_exports, createInstanceFromExist, getUnitInDate, isEmptyObject, isObject, isString, isUndefined, padStart, padZoneStr, prettyUnit, setUnitInDate, undefinedOr };
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EsDayFactory } from './EsDay-
|
|
2
|
-
export {
|
|
1
|
+
import { E as EsDayFactory } from './EsDay-KXQgnL1r.js';
|
|
2
|
+
export { D as DateType, a as EsDay, c as EsDayFactoryParserFn, d as EsDayPlugin, P as PrettyUnit, b as PrettyUnitType, U as UnitType } from './EsDay-KXQgnL1r.js';
|
|
3
3
|
|
|
4
4
|
declare const esday: EsDayFactory;
|
|
5
5
|
|
package/index.js
CHANGED
|
@@ -1,68 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
// src/core/constant.ts
|
|
4
|
-
var MS = "millisecond";
|
|
5
|
-
var S = "second";
|
|
6
|
-
var MIN = "minute";
|
|
7
|
-
var H = "hour";
|
|
8
|
-
var D = "day";
|
|
9
|
-
var W = "week";
|
|
10
|
-
var M = "month";
|
|
11
|
-
var Q = "quarter";
|
|
12
|
-
var Y = "year";
|
|
13
|
-
var DATE = "date";
|
|
14
|
-
var FORMAT_DEFAULT = "YYYY-MM-DDTHH:mm:ssZ";
|
|
15
|
-
var INVALID_DATE_STRING = "Invalid Date";
|
|
16
|
-
var REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
|
|
17
|
-
var REGEX_FORMAT = /\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
|
|
18
|
-
function prettyUnit(u) {
|
|
19
|
-
const special = {
|
|
20
|
-
M,
|
|
21
|
-
y: Y,
|
|
22
|
-
w: W,
|
|
23
|
-
d: D,
|
|
24
|
-
D: DATE,
|
|
25
|
-
h: H,
|
|
26
|
-
m: MIN,
|
|
27
|
-
s: S,
|
|
28
|
-
ms: MS,
|
|
29
|
-
Q
|
|
30
|
-
};
|
|
31
|
-
return special[u] || String(u || "").toLowerCase().replace(/s$/, "");
|
|
32
|
-
}
|
|
33
|
-
function isUndefined(value) {
|
|
34
|
-
return value === void 0;
|
|
35
|
-
}
|
|
36
|
-
function callDateGetOrSet(date, field, utc, value) {
|
|
37
|
-
if (!isUndefined(value) && field !== "Day") {
|
|
38
|
-
date[`set${utc ? "UTC" : ""}${field}`](...isArray(value) ? value : [value]);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
return date[`get${utc ? "UTC" : ""}${field}`]();
|
|
42
|
-
}
|
|
43
|
-
function getAllFieldsInDate(date, utc) {
|
|
44
|
-
return {
|
|
45
|
-
year: callDateGetOrSet(date, "FullYear", utc),
|
|
46
|
-
month: callDateGetOrSet(date, "Month", utc),
|
|
47
|
-
date: callDateGetOrSet(date, "Date", utc),
|
|
48
|
-
day: callDateGetOrSet(date, "Day", utc),
|
|
49
|
-
hour: callDateGetOrSet(date, "Hours", utc),
|
|
50
|
-
minute: callDateGetOrSet(date, "Minutes", utc),
|
|
51
|
-
second: callDateGetOrSet(date, "Seconds", utc),
|
|
52
|
-
millisecond: callDateGetOrSet(date, "Milliseconds", utc)
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function padStart(str, length, pad) {
|
|
56
|
-
str = String(str);
|
|
57
|
-
if (!str || str.length >= length)
|
|
58
|
-
return str;
|
|
59
|
-
return `${Array.from({ length: length + 1 - str.length }).join(pad)}${str}`;
|
|
60
|
-
}
|
|
61
|
-
function wrapperInst(date, instance) {
|
|
62
|
-
const newInst = instance.clone();
|
|
63
|
-
newInst["$d"] = new Date(date);
|
|
64
|
-
return newInst;
|
|
65
|
-
}
|
|
1
|
+
import { constant_exports, getUnitInDate, prettyUnit, setUnitInDate, isObject, createInstanceFromExist, padZoneStr, isUndefined, isEmptyObject, padStart } from './chunk-SQBPUYUY.js';
|
|
66
2
|
|
|
67
3
|
// src/core/Impl/add.ts
|
|
68
4
|
function addImpl(that, number, units) {
|
|
@@ -73,16 +9,16 @@ function addImpl(that, number, units) {
|
|
|
73
9
|
newInstance["$d"].setDate($d.getDate() + Math.round(multiplier * number));
|
|
74
10
|
return newInstance;
|
|
75
11
|
};
|
|
76
|
-
if (unit ===
|
|
12
|
+
if (unit === constant_exports.MONTH) {
|
|
77
13
|
return that.set("month", that.get("month") + number);
|
|
78
14
|
}
|
|
79
|
-
if (unit ===
|
|
15
|
+
if (unit === constant_exports.YEAR) {
|
|
80
16
|
return that.set("year", that.get("year") + number);
|
|
81
17
|
}
|
|
82
|
-
if (unit === DATE || unit ===
|
|
18
|
+
if (unit === constant_exports.DATE || unit === constant_exports.DAY) {
|
|
83
19
|
return instanceFactorySet(1);
|
|
84
20
|
}
|
|
85
|
-
if (unit ===
|
|
21
|
+
if (unit === constant_exports.WEEK) {
|
|
86
22
|
return instanceFactorySet(7);
|
|
87
23
|
}
|
|
88
24
|
const step = {
|
|
@@ -91,132 +27,158 @@ function addImpl(that, number, units) {
|
|
|
91
27
|
second: 1e3
|
|
92
28
|
}[unit] || 1;
|
|
93
29
|
const nextTimeStamp = $d.getTime() + number * step;
|
|
94
|
-
return
|
|
30
|
+
return createInstanceFromExist(new Date(nextTimeStamp), that);
|
|
95
31
|
}
|
|
96
32
|
|
|
97
33
|
// src/core/Impl/format.ts
|
|
98
34
|
function formatImpl(that, formatStr) {
|
|
99
35
|
if (!that.isValid())
|
|
100
|
-
return INVALID_DATE_STRING;
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const str = formatStr || FORMAT_DEFAULT;
|
|
104
|
-
const get$H = (num) => padStart(dates.hour % 12 || 12, num, "0");
|
|
36
|
+
return constant_exports.INVALID_DATE_STRING;
|
|
37
|
+
const str = formatStr || constant_exports.FORMAT_DEFAULT;
|
|
38
|
+
const get$H = (num) => padStart(that.hour() % 12 || 12, num, "0");
|
|
105
39
|
const meridiemFunc = (hour, _minute, isLowercase) => {
|
|
106
40
|
const m = hour < 12 ? "AM" : "PM";
|
|
107
41
|
return isLowercase ? m.toLowerCase() : m;
|
|
108
42
|
};
|
|
43
|
+
const zoneStr = padZoneStr(that.utcOffset());
|
|
44
|
+
const $year = that.year();
|
|
45
|
+
const $month = that.month();
|
|
46
|
+
const $date = that.date();
|
|
47
|
+
const $day = that.day();
|
|
48
|
+
const $hour = that.hour();
|
|
49
|
+
const $minute = that.minute();
|
|
50
|
+
const $second = that.second();
|
|
51
|
+
const $millisecond = that.millisecond();
|
|
109
52
|
const matches = (match) => {
|
|
110
53
|
switch (match) {
|
|
111
54
|
case "YY":
|
|
112
|
-
return String(
|
|
55
|
+
return String($year).slice(-2);
|
|
113
56
|
case "YYYY":
|
|
114
|
-
return padStart(
|
|
57
|
+
return padStart($year, 4, "0");
|
|
115
58
|
case "M":
|
|
116
|
-
return
|
|
59
|
+
return $month + 1;
|
|
117
60
|
case "MM":
|
|
118
|
-
return padStart(
|
|
61
|
+
return padStart($month + 1, 2, "0");
|
|
119
62
|
case "D":
|
|
120
|
-
return
|
|
63
|
+
return $date;
|
|
121
64
|
case "DD":
|
|
122
|
-
return padStart(
|
|
65
|
+
return padStart($date, 2, "0");
|
|
123
66
|
case "d":
|
|
124
|
-
return String(
|
|
67
|
+
return String($day);
|
|
125
68
|
case "H":
|
|
126
|
-
return String(
|
|
69
|
+
return String($hour);
|
|
127
70
|
case "HH":
|
|
128
|
-
return padStart(
|
|
71
|
+
return padStart($hour, 2, "0");
|
|
129
72
|
case "h":
|
|
130
73
|
return get$H(1);
|
|
131
74
|
case "hh":
|
|
132
75
|
return get$H(2);
|
|
133
76
|
case "a":
|
|
134
|
-
return meridiemFunc(
|
|
77
|
+
return meridiemFunc($hour, $minute, true);
|
|
135
78
|
case "A":
|
|
136
|
-
return meridiemFunc(
|
|
79
|
+
return meridiemFunc($hour, $minute, false);
|
|
137
80
|
case "m":
|
|
138
|
-
return String(
|
|
81
|
+
return String($minute);
|
|
139
82
|
case "mm":
|
|
140
|
-
return padStart(
|
|
83
|
+
return padStart($minute, 2, "0");
|
|
141
84
|
case "s":
|
|
142
|
-
return String(
|
|
85
|
+
return String($second);
|
|
143
86
|
case "ss":
|
|
144
|
-
return padStart(
|
|
87
|
+
return padStart($second, 2, "0");
|
|
145
88
|
case "SSS":
|
|
146
|
-
return padStart(
|
|
89
|
+
return padStart($millisecond, 3, "0");
|
|
90
|
+
case "Z":
|
|
91
|
+
return zoneStr;
|
|
147
92
|
}
|
|
148
93
|
return null;
|
|
149
94
|
};
|
|
150
|
-
return str.replace(REGEX_FORMAT, (match, $1) => $1 || matches(match));
|
|
95
|
+
return str.replace(constant_exports.REGEX_FORMAT, (match, $1) => $1 || matches(match));
|
|
151
96
|
}
|
|
152
97
|
|
|
153
98
|
// src/core/Impl/startOf.ts
|
|
154
99
|
function startOfImpl(that, unit, reverse = false) {
|
|
155
|
-
const result = that.
|
|
156
|
-
const
|
|
100
|
+
const result = that.clone();
|
|
101
|
+
const setterFunc = result["$set"];
|
|
157
102
|
const instanceFactorySet = (method, slice) => {
|
|
158
103
|
const argumentStart = [0, 0, 0, 0];
|
|
159
104
|
const argumentEnd = [23, 59, 59, 999];
|
|
160
105
|
const argument = reverse ? argumentEnd.slice(slice) : argumentStart.slice(slice);
|
|
161
|
-
|
|
106
|
+
setterFunc.call(result, method, argument);
|
|
162
107
|
};
|
|
163
|
-
const instanceFactory = (
|
|
164
|
-
|
|
108
|
+
const instanceFactory = (date, month) => {
|
|
109
|
+
setterFunc.call(result, constant_exports.MONTH, [month, date]);
|
|
165
110
|
};
|
|
166
|
-
const $
|
|
111
|
+
const $month = result.month();
|
|
112
|
+
const $date = result.date();
|
|
113
|
+
const $day = result.day();
|
|
167
114
|
switch (prettyUnit(unit)) {
|
|
168
|
-
case
|
|
115
|
+
case constant_exports.YEAR:
|
|
169
116
|
reverse ? instanceFactory(31, 11) : instanceFactory(1, 0);
|
|
170
|
-
instanceFactorySet(
|
|
117
|
+
instanceFactorySet(constant_exports.HOUR, 0);
|
|
171
118
|
break;
|
|
172
|
-
case
|
|
173
|
-
reverse ? instanceFactory(0, $
|
|
174
|
-
instanceFactorySet(
|
|
119
|
+
case constant_exports.MONTH:
|
|
120
|
+
reverse ? instanceFactory(0, $month + 1) : instanceFactory(1, $month);
|
|
121
|
+
instanceFactorySet(constant_exports.HOUR, 0);
|
|
175
122
|
break;
|
|
176
|
-
case
|
|
177
|
-
const
|
|
178
|
-
const diff = (
|
|
179
|
-
|
|
180
|
-
instanceFactorySet(
|
|
123
|
+
case constant_exports.WEEK: {
|
|
124
|
+
const weekStart = constant_exports.INDEX_MONDAY;
|
|
125
|
+
const diff = ($day < weekStart ? $day + 7 : $day) - weekStart;
|
|
126
|
+
instanceFactory(reverse ? $date + (6 - diff) : $date - diff, $month);
|
|
127
|
+
instanceFactorySet(constant_exports.HOUR, 0);
|
|
181
128
|
break;
|
|
182
129
|
}
|
|
183
|
-
case
|
|
184
|
-
case DATE:
|
|
185
|
-
instanceFactorySet(
|
|
130
|
+
case constant_exports.DAY:
|
|
131
|
+
case constant_exports.DATE:
|
|
132
|
+
instanceFactorySet(constant_exports.HOUR, 0);
|
|
186
133
|
break;
|
|
187
|
-
case
|
|
188
|
-
instanceFactorySet(
|
|
134
|
+
case constant_exports.HOUR:
|
|
135
|
+
instanceFactorySet(constant_exports.MIN, 1);
|
|
189
136
|
break;
|
|
190
|
-
case MIN:
|
|
191
|
-
instanceFactorySet(
|
|
137
|
+
case constant_exports.MIN:
|
|
138
|
+
instanceFactorySet(constant_exports.SECOND, 2);
|
|
192
139
|
break;
|
|
193
|
-
case
|
|
194
|
-
instanceFactorySet(
|
|
140
|
+
case constant_exports.SECOND:
|
|
141
|
+
instanceFactorySet(constant_exports.MS, 3);
|
|
195
142
|
break;
|
|
196
143
|
}
|
|
197
|
-
return
|
|
144
|
+
return result;
|
|
198
145
|
}
|
|
199
146
|
|
|
200
147
|
// src/core/parseDate.ts
|
|
148
|
+
function parseArrayToDate(dateArray) {
|
|
149
|
+
const dateArrayTuple = [0, 0, 1, 0, 0, 0, 0];
|
|
150
|
+
dateArray.forEach((value, index) => {
|
|
151
|
+
if (value !== void 0) {
|
|
152
|
+
dateArrayTuple[index] = value;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return new Date(...dateArrayTuple);
|
|
156
|
+
}
|
|
201
157
|
function parseDate(date, utc = false) {
|
|
202
|
-
if (isUndefined(date))
|
|
203
|
-
return /* @__PURE__ */ new Date();
|
|
204
158
|
if (date instanceof Date)
|
|
205
159
|
return new Date(date);
|
|
160
|
+
if (date === null)
|
|
161
|
+
return new Date(Number.NaN);
|
|
162
|
+
if (isUndefined(date))
|
|
163
|
+
return /* @__PURE__ */ new Date();
|
|
164
|
+
if (isEmptyObject(date))
|
|
165
|
+
return /* @__PURE__ */ new Date();
|
|
166
|
+
if (Array.isArray(date))
|
|
167
|
+
return parseArrayToDate(date);
|
|
206
168
|
if (typeof date === "string" && !/Z$/i.test(date)) {
|
|
207
|
-
const d = date.match(REGEX_PARSE);
|
|
169
|
+
const d = date.match(constant_exports.REGEX_PARSE);
|
|
208
170
|
if (d) {
|
|
209
|
-
const
|
|
210
|
-
const
|
|
211
|
-
const
|
|
171
|
+
const Y = Number(d[1]);
|
|
172
|
+
const M = Number(d[2]) - 1 || 0;
|
|
173
|
+
const D = Number(d[3] || 1);
|
|
212
174
|
const h = Number(d[4] || 0);
|
|
213
175
|
const m = Number(d[5] || 0);
|
|
214
176
|
const s = Number(d[6] || 0);
|
|
215
177
|
const ms = Number((d[7] || "0").substring(0, 3));
|
|
216
178
|
if (utc) {
|
|
217
|
-
return new Date(Date.UTC(
|
|
179
|
+
return new Date(Date.UTC(Y, M, D, h, m, s, ms));
|
|
218
180
|
}
|
|
219
|
-
return new Date(
|
|
181
|
+
return new Date(Y, M, D, h, m, s, ms);
|
|
220
182
|
}
|
|
221
183
|
}
|
|
222
184
|
return new Date(date);
|
|
@@ -225,27 +187,29 @@ function parseDate(date, utc = false) {
|
|
|
225
187
|
// src/core/EsDay.ts
|
|
226
188
|
var EsDay = class _EsDay {
|
|
227
189
|
$d;
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
this.$
|
|
235
|
-
this
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
190
|
+
/**
|
|
191
|
+
* mainly for plugin compatibility
|
|
192
|
+
* store data such as locale name, utc mode, etc.
|
|
193
|
+
*/
|
|
194
|
+
$conf = {};
|
|
195
|
+
constructor(d, conf) {
|
|
196
|
+
this.$conf = { ...conf };
|
|
197
|
+
this.parse(d);
|
|
198
|
+
}
|
|
199
|
+
parse(d) {
|
|
200
|
+
this.$d = this.$parseDate(d);
|
|
201
|
+
}
|
|
202
|
+
$parseDate(d, utc = false) {
|
|
203
|
+
return parseDate(d, utc);
|
|
204
|
+
}
|
|
205
|
+
isSame(that, units = constant_exports.MS) {
|
|
242
206
|
const other = esday(that);
|
|
243
207
|
return this.startOf(units) <= other && other <= this.endOf(units);
|
|
244
208
|
}
|
|
245
|
-
isAfter(that, units) {
|
|
209
|
+
isAfter(that, units = constant_exports.MS) {
|
|
246
210
|
return esday(that) < this.startOf(units);
|
|
247
211
|
}
|
|
248
|
-
isBefore(that, units) {
|
|
212
|
+
isBefore(that, units = constant_exports.MS) {
|
|
249
213
|
return this.endOf(units) < esday(that);
|
|
250
214
|
}
|
|
251
215
|
// return this milliseconds
|
|
@@ -256,14 +220,19 @@ var EsDay = class _EsDay {
|
|
|
256
220
|
return Math.floor(this.valueOf() / 1e3);
|
|
257
221
|
}
|
|
258
222
|
isValid() {
|
|
259
|
-
return !(this.$d.toString() === INVALID_DATE_STRING);
|
|
223
|
+
return !(this.$d.toString() === constant_exports.INVALID_DATE_STRING);
|
|
260
224
|
}
|
|
261
225
|
clone() {
|
|
262
|
-
|
|
226
|
+
const newInst = new _EsDay(this.toDate());
|
|
227
|
+
newInst.$conf = { ...this.$conf };
|
|
228
|
+
return newInst;
|
|
263
229
|
}
|
|
264
230
|
format(formatStr) {
|
|
265
231
|
return formatImpl(this, formatStr);
|
|
266
232
|
}
|
|
233
|
+
utcOffset() {
|
|
234
|
+
return -Math.round(this.$d.getTimezoneOffset() / 15) * 15;
|
|
235
|
+
}
|
|
267
236
|
startOf(units) {
|
|
268
237
|
return startOfImpl(this, units);
|
|
269
238
|
}
|
|
@@ -277,10 +246,10 @@ var EsDay = class _EsDay {
|
|
|
277
246
|
return this.add(-number, units);
|
|
278
247
|
}
|
|
279
248
|
get(units) {
|
|
280
|
-
return
|
|
249
|
+
return getUnitInDate(this.$d, units);
|
|
281
250
|
}
|
|
282
|
-
set(
|
|
283
|
-
return this.clone().$set(
|
|
251
|
+
set(unit, ...values) {
|
|
252
|
+
return this.clone().$set(unit, values);
|
|
284
253
|
}
|
|
285
254
|
toDate() {
|
|
286
255
|
return new Date(this.valueOf());
|
|
@@ -294,27 +263,20 @@ var EsDay = class _EsDay {
|
|
|
294
263
|
toString() {
|
|
295
264
|
return this.$d.toUTCString();
|
|
296
265
|
}
|
|
297
|
-
$set(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
[Y]: `FullYear`,
|
|
304
|
-
[H]: `Hours`,
|
|
305
|
-
[MIN]: `Minutes`,
|
|
306
|
-
[S]: `Seconds`,
|
|
307
|
-
[MS]: `Milliseconds`
|
|
308
|
-
}[unit];
|
|
309
|
-
const arg = unit === D ? this.get("date") + (value - this.get("day")) : value;
|
|
310
|
-
callDateGetOrSet(this.$d, name, this.$u, arg);
|
|
266
|
+
$set(unit, values, utc = false) {
|
|
267
|
+
if (prettyUnit(unit) === constant_exports.DAY) {
|
|
268
|
+
setUnitInDate(this.$d, constant_exports.DATE, this.date() + (values[0] - this.day()), utc);
|
|
269
|
+
} else {
|
|
270
|
+
setUnitInDate(this.$d, unit, values, utc);
|
|
271
|
+
}
|
|
311
272
|
return this;
|
|
312
273
|
}
|
|
313
274
|
};
|
|
314
|
-
["year", "month", "date", "day", "hour", "minute", "second", "millisecond"]
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
275
|
+
var helperNames = ["year", "month", "date", "day", "hour", "minute", "second", "millisecond"];
|
|
276
|
+
helperNames.forEach((key) => {
|
|
277
|
+
EsDay.prototype[key] = function(...args) {
|
|
278
|
+
if (args?.length) {
|
|
279
|
+
return this.set(key, ...args);
|
|
318
280
|
} else {
|
|
319
281
|
return this.get(key);
|
|
320
282
|
}
|
|
@@ -326,14 +288,15 @@ var esday = (d, ...others) => {
|
|
|
326
288
|
if (d instanceof EsDay) {
|
|
327
289
|
return d.clone();
|
|
328
290
|
} else {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
291
|
+
const conf = {};
|
|
292
|
+
others.forEach((o, i) => {
|
|
293
|
+
if (isObject(o)) {
|
|
294
|
+
Object.assign(conf, o);
|
|
295
|
+
} else {
|
|
296
|
+
conf[`args_${i + 1}`] = o;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
return new EsDay(d, conf);
|
|
337
300
|
}
|
|
338
301
|
};
|
|
339
302
|
esday.extend = (plugin, option) => {
|
package/locales/en.d.ts
ADDED
package/locales/en.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { en_default as default } from '../chunk-NUV73YDM.js';
|
package/locales/zh.d.ts
ADDED
package/locales/zh.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/locales/zh.ts
|
|
2
|
+
var localeZh = {
|
|
3
|
+
name: "zh",
|
|
4
|
+
weekdays: ["\u661F\u671F\u65E5", "\u661F\u671F\u4E00", "\u661F\u671F\u4E8C", "\u661F\u671F\u4E09", "\u661F\u671F\u56DB", "\u661F\u671F\u4E94", "\u661F\u671F\u516D"],
|
|
5
|
+
weekdaysShort: ["\u5468\u65E5", "\u5468\u4E00", "\u5468\u4E8C", "\u5468\u4E09", "\u5468\u56DB", "\u5468\u4E94", "\u5468\u516D"],
|
|
6
|
+
weekdaysMin: ["\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D"],
|
|
7
|
+
months: ["\u4E00\u6708", "\u4E8C\u6708", "\u4E09\u6708", "\u56DB\u6708", "\u4E94\u6708", "\u516D\u6708", "\u4E03\u6708", "\u516B\u6708", "\u4E5D\u6708", "\u5341\u6708", "\u5341\u4E00\u6708", "\u5341\u4E8C\u6708"],
|
|
8
|
+
monthsShort: ["1\u6708", "2\u6708", "3\u6708", "4\u6708", "5\u6708", "6\u6708", "7\u6708", "8\u6708", "9\u6708", "10\u6708", "11\u6708", "12\u6708"],
|
|
9
|
+
ordinal: (number, period) => {
|
|
10
|
+
switch (period) {
|
|
11
|
+
case "W":
|
|
12
|
+
return `${number}\u5468`;
|
|
13
|
+
default:
|
|
14
|
+
return `${number}\u65E5`;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
weekStart: 1,
|
|
18
|
+
yearStart: 4,
|
|
19
|
+
formats: {
|
|
20
|
+
LT: "HH:mm",
|
|
21
|
+
LTS: "HH:mm:ss",
|
|
22
|
+
L: "YYYY/MM/DD",
|
|
23
|
+
LL: "YYYY\u5E74M\u6708D\u65E5",
|
|
24
|
+
LLL: "YYYY\u5E74M\u6708D\u65E5Ah\u70B9mm\u5206",
|
|
25
|
+
LLLL: "YYYY\u5E74M\u6708D\u65E5ddddAh\u70B9mm\u5206",
|
|
26
|
+
l: "YYYY/M/D",
|
|
27
|
+
ll: "YYYY\u5E74M\u6708D\u65E5",
|
|
28
|
+
lll: "YYYY\u5E74M\u6708D\u65E5 HH:mm",
|
|
29
|
+
llll: "YYYY\u5E74M\u6708D\u65E5dddd HH:mm"
|
|
30
|
+
},
|
|
31
|
+
relativeTime: {
|
|
32
|
+
future: "%s\u540E",
|
|
33
|
+
past: "%s\u524D",
|
|
34
|
+
s: "\u51E0\u79D2",
|
|
35
|
+
m: "1 \u5206\u949F",
|
|
36
|
+
mm: "%d \u5206\u949F",
|
|
37
|
+
h: "1 \u5C0F\u65F6",
|
|
38
|
+
hh: "%d \u5C0F\u65F6",
|
|
39
|
+
d: "1 \u5929",
|
|
40
|
+
dd: "%d \u5929",
|
|
41
|
+
M: "1 \u4E2A\u6708",
|
|
42
|
+
MM: "%d \u4E2A\u6708",
|
|
43
|
+
y: "1 \u5E74",
|
|
44
|
+
yy: "%d \u5E74"
|
|
45
|
+
},
|
|
46
|
+
meridiem: (hour, minute) => {
|
|
47
|
+
const hm = hour * 100 + minute;
|
|
48
|
+
if (hm < 600) {
|
|
49
|
+
return "\u51CC\u6668";
|
|
50
|
+
} else if (hm < 900) {
|
|
51
|
+
return "\u65E9\u4E0A";
|
|
52
|
+
} else if (hm < 1100) {
|
|
53
|
+
return "\u4E0A\u5348";
|
|
54
|
+
} else if (hm < 1300) {
|
|
55
|
+
return "\u4E2D\u5348";
|
|
56
|
+
} else if (hm < 1800) {
|
|
57
|
+
return "\u4E0B\u5348";
|
|
58
|
+
}
|
|
59
|
+
return "\u665A\u4E0A";
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var zh_default = localeZh;
|
|
63
|
+
|
|
64
|
+
export { zh_default as default };
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esday",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"description": "A simple date library fully written in TypeScript",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/g-mero/esday",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/g-mero/esday"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/g-mero/esday/issues"
|
|
14
|
+
},
|
|
7
15
|
"sideEffects": false,
|
|
8
16
|
"exports": {
|
|
9
17
|
".": {
|
|
@@ -22,25 +30,49 @@
|
|
|
22
30
|
"files": [
|
|
23
31
|
"*"
|
|
24
32
|
],
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"radash": "^12.1.0"
|
|
27
|
-
},
|
|
28
33
|
"devDependencies": {
|
|
29
34
|
"@antfu/eslint-config": "^3",
|
|
35
|
+
"@commitlint/cli": "^19.6.1",
|
|
36
|
+
"@commitlint/config-conventional": "^19.6.0",
|
|
30
37
|
"@types/node": "^22.5.2",
|
|
38
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
31
39
|
"@vitest/ui": "latest",
|
|
40
|
+
"commit-and-tag-version": "^12.5.0",
|
|
41
|
+
"cpy-cli": "^5.0.0",
|
|
42
|
+
"dayjs": "^1.11.13",
|
|
32
43
|
"eslint": "^9",
|
|
44
|
+
"husky": "^9.1.7",
|
|
33
45
|
"tsup": "^8.2.4",
|
|
34
46
|
"typescript": "^5.5.4",
|
|
35
47
|
"vite": "latest",
|
|
36
48
|
"vitest": "latest"
|
|
37
49
|
},
|
|
50
|
+
"commit-and-tag-version": {
|
|
51
|
+
"packageFiles": [
|
|
52
|
+
{
|
|
53
|
+
"filename": "package.json",
|
|
54
|
+
"type": "json"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"bumpFiles": [
|
|
58
|
+
{
|
|
59
|
+
"filename": "package.json",
|
|
60
|
+
"type": "json"
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
38
64
|
"scripts": {
|
|
65
|
+
"lint": "pnpm exec eslint .",
|
|
66
|
+
"lint:fix": "pnpm exec eslint . --fix",
|
|
39
67
|
"build": "tsup --dts",
|
|
68
|
+
"type-check": "tsc --noEmit --skipLibCheck",
|
|
40
69
|
"test": "vitest",
|
|
41
70
|
"test:ui": "vitest --ui --api 9527",
|
|
42
71
|
"test:run": "vitest run",
|
|
43
|
-
"
|
|
72
|
+
"test:coverage": "vitest run --coverage",
|
|
73
|
+
"release": "commit-and-tag-version -i CHANGELOG.md --same-file",
|
|
74
|
+
"lint-commits": "commitlint --from b4c0a8614dd7d9997 --to HEAD --verbose",
|
|
75
|
+
"copypkg": "cpy package.json dist/ && cpy README.md dist/ ",
|
|
44
76
|
"pub": "pnpm build && pnpm copypkg && cd dist && pnpm publish"
|
|
45
77
|
}
|
|
46
78
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isString } from '../../chunk-SQBPUYUY.js';
|
|
2
|
+
|
|
1
3
|
// src/plugins/customParseFormat/index.ts
|
|
2
4
|
var formattingTokens = /(\[[^[]*\])|([-_:/.,()\s]+)|([AaQz]|YYYY|YY?|ww?|MM?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|ZZ?)/g;
|
|
3
5
|
var match1 = /\d/;
|
|
@@ -139,19 +141,17 @@ function parseFormattedInput(input, format, utc) {
|
|
|
139
141
|
}
|
|
140
142
|
var customParseFormatPlugin = (_, dayTsClass) => {
|
|
141
143
|
const oldParse = dayTsClass.prototype["parse"];
|
|
142
|
-
dayTsClass.prototype["parse"] = function(d
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const date = parseFormattedInput(d, format, utc);
|
|
144
|
+
dayTsClass.prototype["parse"] = function(d) {
|
|
145
|
+
const format = this["$conf"].args_1;
|
|
146
|
+
if (isString(d) && isString(format)) {
|
|
147
|
+
const date = parseFormattedInput(d, format, !!this["$conf"].utc);
|
|
147
148
|
if (Number.isNaN(date.getTime())) {
|
|
148
149
|
this["$d"] = /* @__PURE__ */ new Date("");
|
|
149
150
|
} else {
|
|
150
151
|
this["$d"] = date;
|
|
151
|
-
this["$u"] = utc;
|
|
152
152
|
}
|
|
153
153
|
} else {
|
|
154
|
-
oldParse.call(this, d
|
|
154
|
+
oldParse.call(this, d);
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { d as EsDayPlugin } from '../../EsDay-KXQgnL1r.js';
|
|
2
|
+
|
|
3
|
+
type ReadonlyTuple<T, N extends number, R extends readonly T[] = []> = R['length'] extends N ? R : ReadonlyTuple<T, N, readonly [T, ...R]>;
|
|
4
|
+
declare module 'esday' {
|
|
5
|
+
interface EsDay {
|
|
6
|
+
locale: (localeName: string) => EsDay;
|
|
7
|
+
}
|
|
8
|
+
interface EsDayFactory {
|
|
9
|
+
/**
|
|
10
|
+
* use locale as global
|
|
11
|
+
*/
|
|
12
|
+
locale: (localeName: string) => EsDayFactory;
|
|
13
|
+
/**
|
|
14
|
+
* register locale
|
|
15
|
+
*/
|
|
16
|
+
registerLocale: (locale: Locale, newName?: string) => EsDayFactory;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
type DayNames<T = string> = ReadonlyTuple<T, 7>;
|
|
20
|
+
type MonthNames<T = string> = ReadonlyTuple<T, 12>;
|
|
21
|
+
interface MonthNamesFunction<T = MonthNames<string>> {
|
|
22
|
+
(format: string): string;
|
|
23
|
+
standalone: T;
|
|
24
|
+
format: T;
|
|
25
|
+
}
|
|
26
|
+
type RelativeTimeElementFunction = (timeValue: string | number, withoutSuffix: boolean, range: string) => string;
|
|
27
|
+
type Format = 'LT' | 'LTS' | 'L' | 'LL' | 'LLL' | 'LLLL' | 'l' | 'll' | 'lll' | 'llll';
|
|
28
|
+
type Relative = 'future' | 'past' | 's' | 'm' | 'mm' | 'h' | 'hh' | 'd' | 'dd' | 'M' | 'MM' | 'y' | 'yy';
|
|
29
|
+
interface Locale {
|
|
30
|
+
/**
|
|
31
|
+
* Name of the locale
|
|
32
|
+
*/
|
|
33
|
+
name: string;
|
|
34
|
+
/**
|
|
35
|
+
* Array of full day names
|
|
36
|
+
* @example ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
|
37
|
+
*/
|
|
38
|
+
weekdays: DayNames;
|
|
39
|
+
/**
|
|
40
|
+
* Array of short versions of day names
|
|
41
|
+
* @example ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
42
|
+
*/
|
|
43
|
+
weekdaysShort?: DayNames;
|
|
44
|
+
weekdaysMin?: DayNames;
|
|
45
|
+
months: MonthNames | MonthNamesFunction;
|
|
46
|
+
monthsShort?: MonthNames | MonthNamesFunction;
|
|
47
|
+
ordinal?: (number: number, period?: 'W') => string;
|
|
48
|
+
weekStart?: number;
|
|
49
|
+
yearStart?: number;
|
|
50
|
+
formats?: Partial<Record<Format, string>>;
|
|
51
|
+
relativeTime?: Record<Relative, string | RelativeTimeElementFunction>;
|
|
52
|
+
meridiem?: (hour: number, minute: number, isLowercase: boolean) => string;
|
|
53
|
+
invalidDate?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare function getLocale(name: string): Locale;
|
|
57
|
+
declare function registerLocale(locale: Locale, rename?: string): void;
|
|
58
|
+
declare module 'esday' {
|
|
59
|
+
interface EsDay {
|
|
60
|
+
locale: (localeName: string) => EsDay;
|
|
61
|
+
}
|
|
62
|
+
interface EsDayFactory {
|
|
63
|
+
/**
|
|
64
|
+
* use locale as global
|
|
65
|
+
*/
|
|
66
|
+
locale: (localeName: string) => EsDayFactory;
|
|
67
|
+
/**
|
|
68
|
+
* register locale
|
|
69
|
+
*/
|
|
70
|
+
registerLocale: (locale: Locale, newName?: string) => EsDayFactory;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
declare const localePlugin: EsDayPlugin<{}>;
|
|
74
|
+
|
|
75
|
+
export { type DayNames, type Locale, type MonthNames, type MonthNamesFunction, type RelativeTimeElementFunction, getLocale, localePlugin, registerLocale };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { en_default } from '../../chunk-NUV73YDM.js';
|
|
2
|
+
import { prettyUnit, constant_exports, undefinedOr } from '../../chunk-SQBPUYUY.js';
|
|
3
|
+
|
|
4
|
+
// src/plugins/locale/index.ts
|
|
5
|
+
var LocaleStore = /* @__PURE__ */ new Map();
|
|
6
|
+
var $localeGlobal = "en";
|
|
7
|
+
function getLocale(name) {
|
|
8
|
+
return LocaleStore.get(name) || en_default;
|
|
9
|
+
}
|
|
10
|
+
function registerLocale(locale, rename) {
|
|
11
|
+
LocaleStore.set(rename || locale.name, locale);
|
|
12
|
+
}
|
|
13
|
+
function getSetPrivateLocaleName(inst, newLocaleName) {
|
|
14
|
+
if (newLocaleName) {
|
|
15
|
+
inst["$locale_name"] = newLocaleName;
|
|
16
|
+
}
|
|
17
|
+
return inst["$locale_name"] || $localeGlobal;
|
|
18
|
+
}
|
|
19
|
+
var localePlugin = (_, dayClass, dayFactory) => {
|
|
20
|
+
dayClass.prototype.$locale = function() {
|
|
21
|
+
return getLocale(getSetPrivateLocaleName(this));
|
|
22
|
+
};
|
|
23
|
+
dayClass.prototype.locale = function(localeName) {
|
|
24
|
+
const inst = this.clone();
|
|
25
|
+
getSetPrivateLocaleName(inst, localeName);
|
|
26
|
+
return inst;
|
|
27
|
+
};
|
|
28
|
+
const oldClone = dayClass.prototype["clone"];
|
|
29
|
+
dayClass.prototype["clone"] = function() {
|
|
30
|
+
const inst = oldClone.call(this);
|
|
31
|
+
getSetPrivateLocaleName(inst, getSetPrivateLocaleName(this));
|
|
32
|
+
return inst;
|
|
33
|
+
};
|
|
34
|
+
const oldParse = dayClass.prototype["parse"];
|
|
35
|
+
dayClass.prototype["parse"] = function(d) {
|
|
36
|
+
oldParse.call(this, d);
|
|
37
|
+
getSetPrivateLocaleName(this, $localeGlobal);
|
|
38
|
+
};
|
|
39
|
+
const oldStartOf = dayClass.prototype["startOf"];
|
|
40
|
+
const oldEndOf = dayClass.prototype["endOf"];
|
|
41
|
+
const fixDiff = (inst, unit) => {
|
|
42
|
+
if (prettyUnit(unit) === constant_exports.WEEK) {
|
|
43
|
+
const defaultStartOfWeek = constant_exports.INDEX_MONDAY;
|
|
44
|
+
const weekStart = undefinedOr(inst.$locale().weekStart, defaultStartOfWeek);
|
|
45
|
+
const diffToDefault = weekStart - defaultStartOfWeek;
|
|
46
|
+
if (diffToDefault !== 0) {
|
|
47
|
+
return inst.add(diffToDefault, constant_exports.DAY);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return inst;
|
|
51
|
+
};
|
|
52
|
+
dayClass.prototype["startOf"] = function(unit) {
|
|
53
|
+
const inst = oldStartOf.call(this, unit);
|
|
54
|
+
return fixDiff(inst, unit);
|
|
55
|
+
};
|
|
56
|
+
dayClass.prototype["endOf"] = function(unit) {
|
|
57
|
+
const inst = oldEndOf.call(this, unit);
|
|
58
|
+
return fixDiff(inst, unit);
|
|
59
|
+
};
|
|
60
|
+
dayFactory.locale = function(localeName) {
|
|
61
|
+
$localeGlobal = localeName;
|
|
62
|
+
return dayFactory;
|
|
63
|
+
};
|
|
64
|
+
dayFactory.registerLocale = function(locale, newName) {
|
|
65
|
+
registerLocale(locale, newName);
|
|
66
|
+
return dayFactory;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { getLocale, localePlugin, registerLocale };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { D as DateType, d as EsDayPlugin } from '../../EsDay-KXQgnL1r.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* utc plugin
|
|
5
|
+
*
|
|
6
|
+
* when utc mode is enabled, get and set methods will use UTC time
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare module 'esday' {
|
|
11
|
+
interface EsDay {
|
|
12
|
+
utc: () => EsDay;
|
|
13
|
+
local: () => EsDay;
|
|
14
|
+
isUTC: () => boolean;
|
|
15
|
+
}
|
|
16
|
+
interface EsDayFactory {
|
|
17
|
+
utc: (date?: DateType, ...others: any[]) => EsDay;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
declare const utcPlugin: EsDayPlugin<{}>;
|
|
21
|
+
|
|
22
|
+
export { utcPlugin };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getUnitInDate, undefinedOr } from '../../chunk-SQBPUYUY.js';
|
|
2
|
+
|
|
3
|
+
// src/plugins/utc/index.ts
|
|
4
|
+
var utcPlugin = (_, dayClass, dayFactory) => {
|
|
5
|
+
dayFactory.utc = (d, ...others) => {
|
|
6
|
+
const inst = dayFactory(d, ...others, { utc: true });
|
|
7
|
+
return inst;
|
|
8
|
+
};
|
|
9
|
+
dayClass.prototype.utc = function() {
|
|
10
|
+
const inst = this.clone();
|
|
11
|
+
inst["$conf"].utc = true;
|
|
12
|
+
return inst;
|
|
13
|
+
};
|
|
14
|
+
dayClass.prototype.local = function() {
|
|
15
|
+
const inst = this.clone();
|
|
16
|
+
inst["$conf"].utc = false;
|
|
17
|
+
return inst;
|
|
18
|
+
};
|
|
19
|
+
dayClass.prototype.isUTC = function() {
|
|
20
|
+
return !!this["$conf"].utc;
|
|
21
|
+
};
|
|
22
|
+
const oldFormat = dayClass.prototype.format;
|
|
23
|
+
dayClass.prototype.format = function(formatStr) {
|
|
24
|
+
const UTC_FORMAT_DEFAULT = "YYYY-MM-DDTHH:mm:ss[Z]";
|
|
25
|
+
const str = formatStr || (this["$conf"].utc ? UTC_FORMAT_DEFAULT : "");
|
|
26
|
+
return oldFormat.call(this, str);
|
|
27
|
+
};
|
|
28
|
+
dayClass.prototype["parse"] = function(date) {
|
|
29
|
+
this["$d"] = this["$parseDate"](date, !!this["$conf"].utc);
|
|
30
|
+
};
|
|
31
|
+
dayClass.prototype["get"] = function(unit) {
|
|
32
|
+
return getUnitInDate(this["$d"], unit, !!this["$conf"].utc);
|
|
33
|
+
};
|
|
34
|
+
const old$set = dayClass.prototype["$set"];
|
|
35
|
+
dayClass.prototype["$set"] = function(unit, value, utc) {
|
|
36
|
+
return old$set.call(this, unit, value, undefinedOr(utc, !!this["$conf"].utc));
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { utcPlugin };
|
package/EsDay-CKy0jEj2.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
type DateType = Date | string | number | EsDay | undefined;
|
|
2
|
-
type PrettyUnitType = 'date' | 'day' | 'week' | 'month' | 'year' | 'hour' | 'minute' | 'second' | 'millisecond';
|
|
3
|
-
type PrettyUnit<T extends UnitType> = T extends 'D' ? 'date' : T extends 'w' ? 'week' : T extends 'M' ? 'month' : T extends 'y' ? 'year' : T extends 'H' ? 'hour' : T extends 'm' ? 'minute' : T extends 's' ? 'second' : T extends 'ms' ? 'millisecond' : T;
|
|
4
|
-
type UnitType = 'y' | 'M' | 'D' | 'w' | 'H' | 'm' | 's' | 'ms' | PrettyUnitType;
|
|
5
|
-
interface AllDateFields {
|
|
6
|
-
year: number;
|
|
7
|
-
month: number;
|
|
8
|
-
/**
|
|
9
|
-
* date in month
|
|
10
|
-
* 1 ~ 31
|
|
11
|
-
*/
|
|
12
|
-
date: number;
|
|
13
|
-
/**
|
|
14
|
-
* day in week
|
|
15
|
-
* 0 ~ 6
|
|
16
|
-
*/
|
|
17
|
-
day: number;
|
|
18
|
-
hour: number;
|
|
19
|
-
minute: number;
|
|
20
|
-
second: number;
|
|
21
|
-
millisecond: number;
|
|
22
|
-
}
|
|
23
|
-
type EsDayFactoryParserFn = (d?: DateType, ...others: any[]) => EsDay;
|
|
24
|
-
interface EsDayFactory {
|
|
25
|
-
(...args: Parameters<EsDayFactoryParserFn>): ReturnType<EsDayFactoryParserFn>;
|
|
26
|
-
utc: EsDayFactoryParserFn;
|
|
27
|
-
extend: <T extends {}>(plugin: EsDayPlugin<T>, option?: T) => EsDayFactory;
|
|
28
|
-
}
|
|
29
|
-
type EsDayPlugin<T extends {}> = (option: T, dayTsClass: typeof EsDay, esday: EsDayFactory) => void;
|
|
30
|
-
|
|
31
|
-
declare interface EsDay {
|
|
32
|
-
year: (() => number) & ((value: number) => EsDay);
|
|
33
|
-
month: (() => number) & ((value: number) => EsDay);
|
|
34
|
-
date: (() => number) & ((value: number) => EsDay);
|
|
35
|
-
day: (() => number) & ((value: number) => EsDay);
|
|
36
|
-
hour: (() => number) & ((value: number) => EsDay);
|
|
37
|
-
minute: (() => number) & ((value: number) => EsDay);
|
|
38
|
-
second: (() => number) & ((value: number) => EsDay);
|
|
39
|
-
millisecond: (() => number) & ((value: number) => EsDay);
|
|
40
|
-
}
|
|
41
|
-
declare class EsDay {
|
|
42
|
-
private $d;
|
|
43
|
-
private $u;
|
|
44
|
-
constructor(d: Exclude<DateType, EsDay>, utc: boolean, ...others: any[]);
|
|
45
|
-
private parse;
|
|
46
|
-
utc(): EsDay;
|
|
47
|
-
isSame(that: DateType, units: UnitType): boolean;
|
|
48
|
-
isAfter(that: DateType, units: UnitType): boolean;
|
|
49
|
-
isBefore(that: DateType, units: UnitType): boolean;
|
|
50
|
-
valueOf(): number;
|
|
51
|
-
unix(): number;
|
|
52
|
-
isValid(): boolean;
|
|
53
|
-
clone(): EsDay;
|
|
54
|
-
format(formatStr: string): string;
|
|
55
|
-
startOf(units: UnitType): EsDay;
|
|
56
|
-
endOf(units: UnitType): EsDay;
|
|
57
|
-
add(number: number, units: UnitType): EsDay;
|
|
58
|
-
subtract(number: number, units: UnitType): EsDay;
|
|
59
|
-
get(units: Exclude<UnitType, 'week' | 'w'>): number;
|
|
60
|
-
set(units: UnitType, value: number): EsDay;
|
|
61
|
-
toDate(): Date;
|
|
62
|
-
toJSON(): string | null;
|
|
63
|
-
toISOString(): string;
|
|
64
|
-
toString(): string;
|
|
65
|
-
private $set;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export { type AllDateFields as A, type DateType as D, type EsDayFactory as E, type PrettyUnitType as P, type UnitType as U, EsDay as a, type PrettyUnit as b, type EsDayFactoryParserFn as c, type EsDayPlugin as d };
|