@hapiboo/date 2.0.3 → 3.0.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/dist/class.d.ts +1 -0
- package/dist/class.js +3 -0
- package/package.json +17 -13
- package/eslint.config.mjs +0 -16
- package/package.dev.json +0 -30
- package/package.public.json +0 -29
- package/src/class.ts +0 -174
- package/src/holiday.ts +0 -102
- package/src/index.ts +0 -6
- package/src/service.ts +0 -43
- package/src/utils.ts +0 -30
- package/tsconfig.base.json +0 -18
- package/tsconfig.dev.json +0 -7
- package/tsconfig.public.json +0 -7
package/dist/class.d.ts
CHANGED
package/dist/class.js
CHANGED
|
@@ -160,5 +160,8 @@ class DateObject {
|
|
|
160
160
|
getHoursDifference(dateToCompare) {
|
|
161
161
|
return luxon_1.Interval.fromDateTimes(this.val, dateToCompare.val).toDuration(['hours', 'minutes']).hours;
|
|
162
162
|
}
|
|
163
|
+
getMilisecondsDifference(dateToCompare) {
|
|
164
|
+
return this.val.diff(dateToCompare.val).as('milliseconds');
|
|
165
|
+
}
|
|
163
166
|
}
|
|
164
167
|
exports.DateObject = DateObject;
|
package/package.json
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hapiboo/date",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "MK13 Studio Hapiboo - date services",
|
|
5
5
|
"author": "MK13 Studio",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
9
15
|
"dependencies": {
|
|
10
16
|
"luxon": "^3.7.1"
|
|
11
17
|
},
|
|
12
18
|
"devDependencies": {
|
|
13
19
|
"@types/luxon": "^3.6.2",
|
|
14
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
15
|
-
"@typescript-eslint/parser": "^8.
|
|
16
|
-
"eslint": "^9.
|
|
17
|
-
"typescript": "5.
|
|
18
|
-
"typescript-eslint": "^8.
|
|
20
|
+
"@typescript-eslint/eslint-plugin": "^8.51.0",
|
|
21
|
+
"@typescript-eslint/parser": "^8.51.0",
|
|
22
|
+
"eslint": "^9.39.2",
|
|
23
|
+
"typescript": "^5.9.3",
|
|
24
|
+
"typescript-eslint": "^8.51.0"
|
|
19
25
|
},
|
|
20
26
|
"scripts": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"s_check": "bash ../../scripts/publish.sh ./",
|
|
27
|
-
"s_publish": "pnpm s_clean && pnpm i -w=false && pnpm s_lint && pnpm s_build && pnpm s_check && pnpm s_dev"
|
|
27
|
+
"version-to-publish": "pnpm exec tsx ../../scripts/version_update.ts packages/date --publish-version",
|
|
28
|
+
"publish-check": "bash ../../scripts/publish.sh ./",
|
|
29
|
+
"version-to-children": "pnpm exec tsx ../../scripts/version_update.ts packages/date --update-children",
|
|
30
|
+
"ci:publish-prepare": "rm -f pnpm-lock.yaml && rm -rf node_modules dist && pnpm install --ignore-workspace --no-frozen-lockfile && eslint 'src/*.ts' && echo \"Linter OK\" && tsc && echo \"Build OK\"",
|
|
31
|
+
"ci:publish": "pnpm ci:publish-prepare && pnpm version-to-publish && pnpm publish-check && pnpm version-to-children"
|
|
28
32
|
}
|
|
29
33
|
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import tseslint from "typescript-eslint";
|
|
2
|
-
import { defineConfig } from "eslint/config";
|
|
3
|
-
|
|
4
|
-
export default defineConfig([
|
|
5
|
-
...tseslint.configs.recommended,
|
|
6
|
-
{
|
|
7
|
-
files: ["**/*.{ts,mts,cts}"],
|
|
8
|
-
rules: {
|
|
9
|
-
"@typescript-eslint/no-namespace": "off",
|
|
10
|
-
indent: ['error', 4],
|
|
11
|
-
'linebreak-style': ['error', 'unix'],
|
|
12
|
-
quotes: ['error', 'single'],
|
|
13
|
-
semi: ['error', 'always'],
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
]);
|
package/package.dev.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hapiboo/date",
|
|
3
|
-
"version": "2.0.4-dev",
|
|
4
|
-
"description": "MK13 Studio Hapiboo - date services",
|
|
5
|
-
"author": "MK13 Studio",
|
|
6
|
-
"license": "ISC",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"s_public": "cp package.public.json package.json",
|
|
11
|
-
"s_dev": "cp package.dev.json package.json",
|
|
12
|
-
"s_clean": "rm -f pnpm-lock.yaml && rm -rf node_modules dist",
|
|
13
|
-
"s_dependency": "cd .. && cd __core && pnpm s_build",
|
|
14
|
-
"s_build": "tsc --project tsconfig.dev.json",
|
|
15
|
-
"s_lint": "eslint 'src/*.ts'",
|
|
16
|
-
"s_lint_fix": "eslint 'src/*.ts' --fix",
|
|
17
|
-
"s_prepare": "pnpm s_clean && pnpm i && pnpm s_lint && pnpm s_build"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"luxon": "^3.7.1"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@types/luxon": "^3.6.2",
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
25
|
-
"@typescript-eslint/parser": "^8.38.0",
|
|
26
|
-
"eslint": "^9.32.0",
|
|
27
|
-
"typescript": "5.8.3",
|
|
28
|
-
"typescript-eslint": "^8.38.0"
|
|
29
|
-
}
|
|
30
|
-
}
|
package/package.public.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hapiboo/date",
|
|
3
|
-
"version": "2.0.3",
|
|
4
|
-
"description": "MK13 Studio Hapiboo - date services",
|
|
5
|
-
"author": "MK13 Studio",
|
|
6
|
-
"license": "ISC",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"s_public": "cp package.public.json package.json",
|
|
11
|
-
"s_dev": "cp package.dev.json package.json",
|
|
12
|
-
"s_clean": "rm -f pnpm-lock.yaml && rm -rf node_modules dist",
|
|
13
|
-
"s_build": "tsc --project tsconfig.public.json",
|
|
14
|
-
"s_lint": "eslint 'src/*.ts'",
|
|
15
|
-
"s_check": "bash ../../scripts/publish.sh ./",
|
|
16
|
-
"s_publish": "pnpm s_clean && pnpm i -w=false && pnpm s_lint && pnpm s_build && pnpm s_check && pnpm s_dev"
|
|
17
|
-
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"luxon": "^3.7.1"
|
|
20
|
-
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"@types/luxon": "^3.6.2",
|
|
23
|
-
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
24
|
-
"@typescript-eslint/parser": "^8.38.0",
|
|
25
|
-
"eslint": "^9.32.0",
|
|
26
|
-
"typescript": "5.8.3",
|
|
27
|
-
"typescript-eslint": "^8.38.0"
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/class.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { DateTime, Duration, Interval } from 'luxon';
|
|
2
|
-
import { dateService } from './service';
|
|
3
|
-
import { holidayService } from './holiday';
|
|
4
|
-
|
|
5
|
-
export class DateObject {
|
|
6
|
-
private val: DateTime;
|
|
7
|
-
|
|
8
|
-
private constructor(val: DateTime) {
|
|
9
|
-
this.val = val;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static set(epochMilliseconds: number): DateObject {
|
|
13
|
-
return new DateObject(DateTime.fromMillis(epochMilliseconds));
|
|
14
|
-
}
|
|
15
|
-
static now(): DateObject {
|
|
16
|
-
return new DateObject(DateTime.local());
|
|
17
|
-
}
|
|
18
|
-
static today(): DateObject {
|
|
19
|
-
const now = DateTime.local();
|
|
20
|
-
return dateService.date(now.year, now.month, now.day);
|
|
21
|
-
}
|
|
22
|
-
static yesterday(): DateObject {
|
|
23
|
-
return DateObject.today().addDay(-1);
|
|
24
|
-
}
|
|
25
|
-
static startOfWeek(): DateObject {
|
|
26
|
-
const today = DateObject.today();
|
|
27
|
-
return today.addDay(1 - today.weekday);
|
|
28
|
-
}
|
|
29
|
-
static startOfMonth(): DateObject {
|
|
30
|
-
const now = DateTime.local();
|
|
31
|
-
return dateService.date(now.year, now.month, 1);
|
|
32
|
-
}
|
|
33
|
-
static startOfYear(): DateObject {
|
|
34
|
-
const now = DateTime.local();
|
|
35
|
-
return dateService.date(now.year, 1, 1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get _value(): string {
|
|
39
|
-
return this.toString();
|
|
40
|
-
}
|
|
41
|
-
get hour(): number {
|
|
42
|
-
return this.val.hour;
|
|
43
|
-
}
|
|
44
|
-
get day(): number {
|
|
45
|
-
return this.val.day;
|
|
46
|
-
}
|
|
47
|
-
get month(): number {
|
|
48
|
-
return this.val.month;
|
|
49
|
-
}
|
|
50
|
-
get year(): number {
|
|
51
|
-
return this.val.year;
|
|
52
|
-
}
|
|
53
|
-
get weekday(): number {
|
|
54
|
-
return this.val.weekday;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
toString(): string {
|
|
58
|
-
return this.val.toString();
|
|
59
|
-
}
|
|
60
|
-
toUtc(): string {
|
|
61
|
-
return this.val.toUTC().toString();
|
|
62
|
-
}
|
|
63
|
-
toDateShort(): string {
|
|
64
|
-
return this.val.toLocaleString(DateTime.DATE_SHORT);
|
|
65
|
-
}
|
|
66
|
-
toLocaleDateShort(locale: string): string {
|
|
67
|
-
return this.val.setLocale(locale).toLocaleString(DateTime.DATE_SHORT);
|
|
68
|
-
}
|
|
69
|
-
toMonthShortString(): string {
|
|
70
|
-
return this.val.toFormat('LLL').toUpperCase();
|
|
71
|
-
}
|
|
72
|
-
toWeekdayString(): string {
|
|
73
|
-
return this.val.toFormat('ccc');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private clone() : DateTime {
|
|
77
|
-
return DateTime.local(this.val.year, this.val.month, this.val.day, this.val.hour, this.val.minute, this.val.second, this.val.millisecond);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
addMilisecond(count: number): DateObject {
|
|
81
|
-
return new DateObject(this.clone().plus(Duration.fromObject({milliseconds: count})));
|
|
82
|
-
}
|
|
83
|
-
addSecond(count: number): DateObject {
|
|
84
|
-
return new DateObject(this.clone().plus(Duration.fromObject({seconds: count})));
|
|
85
|
-
}
|
|
86
|
-
addMinute(count: number): DateObject {
|
|
87
|
-
return new DateObject(this.clone().plus(Duration.fromObject({minutes: count})));
|
|
88
|
-
}
|
|
89
|
-
addHour(count: number): DateObject {
|
|
90
|
-
return new DateObject(this.clone().plus(Duration.fromObject({hours: count})));
|
|
91
|
-
}
|
|
92
|
-
addDay(count: number): DateObject {
|
|
93
|
-
return new DateObject(this.clone().plus(Duration.fromObject({days: count})));
|
|
94
|
-
}
|
|
95
|
-
addMonth(count: number): DateObject {
|
|
96
|
-
return new DateObject(this.clone().plus(Duration.fromObject({months: count})));
|
|
97
|
-
}
|
|
98
|
-
addYear(count: number): DateObject {
|
|
99
|
-
return new DateObject(this.clone().plus(Duration.fromObject({years: count})));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
resetYear(): DateObject {
|
|
103
|
-
return new DateObject(this.clone().set({ year: 2000 }));
|
|
104
|
-
}
|
|
105
|
-
resetDay(): DateObject {
|
|
106
|
-
return new DateObject(this.resetYear().val.set({ month: 1, day: 1 }));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
removeMinutes(): DateObject {
|
|
110
|
-
return new DateObject(this.clone().set({ minute: 0, second: 0, millisecond: 0 }));
|
|
111
|
-
}
|
|
112
|
-
removeHours(): DateObject {
|
|
113
|
-
return new DateObject(this.removeMinutes().val.set({ hour: 0 }));
|
|
114
|
-
}
|
|
115
|
-
removeDays(): DateObject {
|
|
116
|
-
return new DateObject(this.removeHours().val.set({ day: 1 }));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
equals(dateToCompare: DateObject): boolean {
|
|
120
|
-
return +this.val === +dateToCompare.val;
|
|
121
|
-
}
|
|
122
|
-
sameDay(dateToCompare: DateObject): boolean {
|
|
123
|
-
return this.val.hasSame(dateToCompare.val, 'day') &&
|
|
124
|
-
this.val.hasSame(dateToCompare.val, 'month') &&
|
|
125
|
-
this.val.hasSame(dateToCompare.val, 'year');
|
|
126
|
-
}
|
|
127
|
-
isDateBetween(startDate: DateObject, endDate: DateObject): boolean {
|
|
128
|
-
return this.val >= startDate.val && this.val <= endDate.val;
|
|
129
|
-
}
|
|
130
|
-
isGreater(dateToCompare: DateObject): boolean {
|
|
131
|
-
return this.val > dateToCompare.val;
|
|
132
|
-
}
|
|
133
|
-
isGreaterOrEqual(dateToCompare: DateObject): boolean {
|
|
134
|
-
return this.val >= dateToCompare.val;
|
|
135
|
-
}
|
|
136
|
-
isSmaller(dateToCompare: DateObject): boolean {
|
|
137
|
-
return this.val < dateToCompare.val;
|
|
138
|
-
}
|
|
139
|
-
isSmallerOrEqual(dateToCompare: DateObject): boolean {
|
|
140
|
-
return this.val <= dateToCompare.val;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
compare(dateToCompare: DateObject): number {
|
|
144
|
-
if (this.equals(dateToCompare)) {
|
|
145
|
-
return 0;
|
|
146
|
-
} else if (this.isGreater(dateToCompare)) {
|
|
147
|
-
return 1;
|
|
148
|
-
} else {
|
|
149
|
-
return -1;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
isWeekday(): boolean {
|
|
154
|
-
return this.weekday < 6;
|
|
155
|
-
}
|
|
156
|
-
isWeekend(): boolean {
|
|
157
|
-
return this.weekday > 5;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
isHoliday(): boolean {
|
|
161
|
-
return holidayService.isHoliday(this);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
valueOf(): number {
|
|
165
|
-
return this.val.valueOf();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
getDaysDifference(dateToCompare: DateObject): number {
|
|
169
|
-
return Interval.fromDateTimes(this.val, dateToCompare.val).count('day');
|
|
170
|
-
}
|
|
171
|
-
getHoursDifference(dateToCompare: DateObject): number {
|
|
172
|
-
return Interval.fromDateTimes(this.val, dateToCompare.val).toDuration(['hours', 'minutes']).hours;
|
|
173
|
-
}
|
|
174
|
-
}
|
package/src/holiday.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { dateService } from './service';
|
|
2
|
-
import { DateObject } from './class';
|
|
3
|
-
|
|
4
|
-
export class Holiday {
|
|
5
|
-
name: string;
|
|
6
|
-
month: number;
|
|
7
|
-
day: number | { weekday: number, count: number};
|
|
8
|
-
|
|
9
|
-
constructor(name: string, month: number, day: number | { weekday: number, count: number}) {
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.month = month;
|
|
12
|
-
this.day = day;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function getNthDay(year: number, month: number, weekday: number, count: number): DateObject {
|
|
17
|
-
const firstDayOfMonth = dateService.date(year, month, 1);
|
|
18
|
-
|
|
19
|
-
// is target day before or after first day
|
|
20
|
-
const offsetThreshold = firstDayOfMonth.weekday - weekday;
|
|
21
|
-
|
|
22
|
-
let offsetFromTargetDay: number;
|
|
23
|
-
if (offsetThreshold > 0) {
|
|
24
|
-
// get to target day if target is after first day
|
|
25
|
-
offsetFromTargetDay = 7 - offsetThreshold;
|
|
26
|
-
} else {
|
|
27
|
-
// reverse threshold to get to target from first day
|
|
28
|
-
offsetFromTargetDay = offsetThreshold * -1;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const firstOccurenceOfTargetDay = firstDayOfMonth.addDay(offsetFromTargetDay);
|
|
32
|
-
const nthDay = firstOccurenceOfTargetDay.addDay((count - 1) * 7);
|
|
33
|
-
|
|
34
|
-
return nthDay;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export namespace holidayService {
|
|
38
|
-
const _list: Holiday[] = [];
|
|
39
|
-
|
|
40
|
-
type KnownHolidays = {
|
|
41
|
-
ChristmasEve: Holiday;
|
|
42
|
-
ChristmasDay: Holiday;
|
|
43
|
-
Christmas2ndDay: Holiday;
|
|
44
|
-
NewYearDay: Holiday;
|
|
45
|
-
USIndependenceDay: Holiday;
|
|
46
|
-
USThanksgivingDay: Holiday;
|
|
47
|
-
USMemorialDay: Holiday;
|
|
48
|
-
USLaborDay: Holiday;
|
|
49
|
-
PLIndependenceDay: Holiday;
|
|
50
|
-
PLLaborDay: Holiday;
|
|
51
|
-
PLConstitutionDay: Holiday;
|
|
52
|
-
PLAllSaintsDay: Holiday;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const known: KnownHolidays = {
|
|
56
|
-
ChristmasEve: new Holiday('Christmas Day', 12, 24),
|
|
57
|
-
ChristmasDay: new Holiday('Christmas Day', 12, 25),
|
|
58
|
-
Christmas2ndDay: new Holiday('Christmas Day', 12, 26),
|
|
59
|
-
NewYearDay: new Holiday('New Year\'s Day', 1, 2),
|
|
60
|
-
USIndependenceDay: new Holiday('Independence Day', 7, 4),
|
|
61
|
-
USThanksgivingDay: new Holiday('Thanksgiving Day', 11, { weekday: 4, count: 4 }),
|
|
62
|
-
USMemorialDay: new Holiday('Memorial Day', 5, { weekday: 1, count: -1 }),
|
|
63
|
-
USLaborDay: new Holiday('Labor Day', 9, { weekday: 1, count: 1 }),
|
|
64
|
-
PLIndependenceDay: new Holiday('Independence Day', 11, 11),
|
|
65
|
-
PLConstitutionDay: new Holiday('Constitution Day', 5, 3),
|
|
66
|
-
PLLaborDay: new Holiday('Labor Day', 5, 1),
|
|
67
|
-
PLAllSaintsDay: new Holiday('All Saints Day', 11, 1),
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export function registerHoliday(holiday: Holiday){
|
|
71
|
-
_list.push(holiday);
|
|
72
|
-
}
|
|
73
|
-
export function isHoliday(date: DateObject): boolean {
|
|
74
|
-
return _list.some((holiday) => {
|
|
75
|
-
return checkHoliday(date, holiday);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
export function checkHoliday(date: DateObject, holiday: Holiday): boolean{
|
|
79
|
-
const justDate = date.removeHours();
|
|
80
|
-
let holy: DateObject;
|
|
81
|
-
|
|
82
|
-
if (typeof holiday.day === 'number') {
|
|
83
|
-
//fixed holiday
|
|
84
|
-
holy = dateService.date(justDate.year, holiday.month, holiday.day);
|
|
85
|
-
} else {
|
|
86
|
-
//moveable holiday
|
|
87
|
-
if (holiday.day.count > 1) {
|
|
88
|
-
//we're counting from beginning
|
|
89
|
-
//let's get nth weekday in specific month
|
|
90
|
-
holy = getNthDay(justDate.year, holiday.month, holiday.day.weekday, holiday.day.count);
|
|
91
|
-
} else {
|
|
92
|
-
//we're counting from the end
|
|
93
|
-
//let's get started from the first weekday in next month
|
|
94
|
-
holy = getNthDay(
|
|
95
|
-
holiday.month === 12 ? justDate.year + 1 : justDate.year,
|
|
96
|
-
holiday.month === 12 ? 1 : holiday.month + 1,
|
|
97
|
-
holiday.day.weekday, 1).addDay(7 * holiday.day.count);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return justDate.sameDay(holy);
|
|
101
|
-
}
|
|
102
|
-
}
|
package/src/index.ts
DELETED
package/src/service.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { DateTime, Settings } from 'luxon';
|
|
2
|
-
import { DateObject } from './class';
|
|
3
|
-
|
|
4
|
-
Settings.defaultZone = 'utc';
|
|
5
|
-
|
|
6
|
-
export namespace dateService {
|
|
7
|
-
|
|
8
|
-
export function initialize(defaultZoneName: string, defaultLocaleName: string) {
|
|
9
|
-
Settings.defaultZone = defaultZoneName;
|
|
10
|
-
Settings.defaultLocale = defaultLocaleName;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function parseUtcDate(datetime: string | undefined) : DateObject | undefined {
|
|
14
|
-
if (datetime) {
|
|
15
|
-
const temp = DateTime.fromISO(datetime);
|
|
16
|
-
if (temp) {
|
|
17
|
-
if (temp.isValid) {
|
|
18
|
-
return DateObject.set(temp.setZone(Settings.defaultZone).valueOf());
|
|
19
|
-
} else {
|
|
20
|
-
console.error(`Invalid date parsing value: '${datetime}'`);
|
|
21
|
-
console.error(temp.invalidReason);
|
|
22
|
-
console.error(temp.invalidExplanation);
|
|
23
|
-
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
} else {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function date(year: number, month: number, day: number) : DateObject {
|
|
35
|
-
return DateObject.set(DateTime.local(year, month, day).valueOf());
|
|
36
|
-
}
|
|
37
|
-
export function datetime(year: number, month: number, day: number, hour: number, minute: number): DateObject {
|
|
38
|
-
return DateObject.set(DateTime.local(year, month, day, hour, minute).valueOf());
|
|
39
|
-
}
|
|
40
|
-
export function daytime(day: DateObject, hour: number = 0, minute: number = 0): DateObject {
|
|
41
|
-
return datetime(day.year, day.month, day.day, hour, minute);
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { dateService } from './service';
|
|
2
|
-
import { DateObject } from './class';
|
|
3
|
-
|
|
4
|
-
export namespace dateUtils {
|
|
5
|
-
|
|
6
|
-
export function checkPeriod(value: DateObject, start?: DateObject, stop?: DateObject): boolean {
|
|
7
|
-
if (!start) {
|
|
8
|
-
start = dateService.date(0, 1, 1);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (!stop) {
|
|
12
|
-
stop = dateService.date(3000, 12, 31);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return checkDatePeriod(value, start, stop);
|
|
16
|
-
}
|
|
17
|
-
export function checkDatePeriod(value: DateObject, start: DateObject, stop: DateObject): boolean {
|
|
18
|
-
return value >= start && value <= stop;
|
|
19
|
-
}
|
|
20
|
-
export function checkSameYearPeriod(value: DateObject, start: DateObject, stop: DateObject): boolean {
|
|
21
|
-
return checkDatePeriod(value, start, stop);
|
|
22
|
-
}
|
|
23
|
-
export function checkSameDayPeriod(value: DateObject, start: DateObject, stop: DateObject): boolean {
|
|
24
|
-
const val = value.resetDay();
|
|
25
|
-
const str = start.resetDay();
|
|
26
|
-
const stp = stop.resetDay();
|
|
27
|
-
|
|
28
|
-
return checkDatePeriod(val, str, stp);
|
|
29
|
-
}
|
|
30
|
-
}
|
package/tsconfig.base.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["ES2020"],
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"moduleResolution": "node",
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"declaration": true,
|
|
15
|
-
},
|
|
16
|
-
"include": ["src/**/*"],
|
|
17
|
-
"exclude": ["node_modules", "dist"]
|
|
18
|
-
}
|
package/tsconfig.dev.json
DELETED