@webtypen/webframez-core 0.2.25 → 0.2.26
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.
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DateFunctions = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
class DateFunctionsFacade {
|
|
9
|
+
formatDateRange(start, end) {
|
|
10
|
+
const startDate = (0, moment_1.default)(start, "YYYY-MM-DD", true);
|
|
11
|
+
const endDate = (0, moment_1.default)(end, "YYYY-MM-DD", true);
|
|
12
|
+
if (!startDate.isValid() || !endDate.isValid()) {
|
|
13
|
+
throw new Error("Ungültiges Datumsformat");
|
|
14
|
+
}
|
|
15
|
+
const startYear = startDate.year();
|
|
16
|
+
const endYear = endDate.year();
|
|
17
|
+
// Ganzes Jahr
|
|
18
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31 && startYear === endYear) {
|
|
19
|
+
return `${startYear}`;
|
|
20
|
+
}
|
|
21
|
+
// Semester
|
|
22
|
+
if (startYear === endYear) {
|
|
23
|
+
// 1. Halbjahr: 01.01 - 30.06
|
|
24
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 5 && endDate.date() === 30) {
|
|
25
|
+
return `1. Halbjahr ${startYear}`;
|
|
26
|
+
}
|
|
27
|
+
// 2. Halbjahr: 01.07 - 31.12
|
|
28
|
+
if (startDate.month() === 6 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31) {
|
|
29
|
+
return `2. Halbjahr ${startYear}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Quartal
|
|
33
|
+
if (startYear === endYear) {
|
|
34
|
+
// Q1: 01.01 - 31.03
|
|
35
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 2 && endDate.date() === 31) {
|
|
36
|
+
return `Q1 ${startYear}`;
|
|
37
|
+
}
|
|
38
|
+
// Q2: 01.04 - 30.06
|
|
39
|
+
if (startDate.month() === 3 && startDate.date() === 1 && endDate.month() === 5 && endDate.date() === 30) {
|
|
40
|
+
return `Q2 ${startYear}`;
|
|
41
|
+
}
|
|
42
|
+
// Q3: 01.07 - 30.09
|
|
43
|
+
if (startDate.month() === 6 && startDate.date() === 1 && endDate.month() === 8 && endDate.date() === 30) {
|
|
44
|
+
return `Q3 ${startYear}`;
|
|
45
|
+
}
|
|
46
|
+
// Q4: 01.10 - 31.12
|
|
47
|
+
if (startDate.month() === 9 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31) {
|
|
48
|
+
return `Q4 ${startYear}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Monat
|
|
52
|
+
if (startYear === endYear && startDate.month() === endDate.month()) {
|
|
53
|
+
if (startDate.date() === 1) {
|
|
54
|
+
const lastDay = startDate.clone().endOf("month").date();
|
|
55
|
+
if (endDate.date() === lastDay) {
|
|
56
|
+
const months = [
|
|
57
|
+
"Januar",
|
|
58
|
+
"Februar",
|
|
59
|
+
"März",
|
|
60
|
+
"April",
|
|
61
|
+
"Mai",
|
|
62
|
+
"Juni",
|
|
63
|
+
"Juli",
|
|
64
|
+
"August",
|
|
65
|
+
"September",
|
|
66
|
+
"Oktober",
|
|
67
|
+
"November",
|
|
68
|
+
"Dezember",
|
|
69
|
+
];
|
|
70
|
+
return `${months[startDate.month()]} ${startYear}`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Kalenderwoche (KW)
|
|
75
|
+
const diffDays = endDate.diff(startDate, "days");
|
|
76
|
+
if (diffDays === 6 &&
|
|
77
|
+
startDate.day() === 1 && // Montag
|
|
78
|
+
endDate.day() === 0 // Sonntag
|
|
79
|
+
) {
|
|
80
|
+
const weekNumber = startDate.isoWeek();
|
|
81
|
+
return `KW-${weekNumber} ${startYear}`;
|
|
82
|
+
}
|
|
83
|
+
// Standard
|
|
84
|
+
return `${startDate.format("DD.MM.YYYY")} - ${endDate.format("DD.MM.YYYY")}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.DateFunctions = new DateFunctionsFacade();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Config"), exports);
|
|
18
|
+
__exportStar(require("./Functions/DateFunctions"), exports);
|
|
18
19
|
__exportStar(require("./Functions/FileFunctions"), exports);
|
|
19
20
|
__exportStar(require("./Functions/StringFunctions"), exports);
|
|
20
21
|
__exportStar(require("./Functions/NumericFunctions"), exports);
|
package/package.json
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
|
|
3
|
+
class DateFunctionsFacade {
|
|
4
|
+
formatDateRange(start: string, end: string): string {
|
|
5
|
+
const startDate = moment(start, "YYYY-MM-DD", true);
|
|
6
|
+
const endDate = moment(end, "YYYY-MM-DD", true);
|
|
7
|
+
|
|
8
|
+
if (!startDate.isValid() || !endDate.isValid()) {
|
|
9
|
+
throw new Error("Ungültiges Datumsformat");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const startYear = startDate.year();
|
|
13
|
+
const endYear = endDate.year();
|
|
14
|
+
|
|
15
|
+
// Ganzes Jahr
|
|
16
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31 && startYear === endYear) {
|
|
17
|
+
return `${startYear}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Semester
|
|
21
|
+
if (startYear === endYear) {
|
|
22
|
+
// 1. Halbjahr: 01.01 - 30.06
|
|
23
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 5 && endDate.date() === 30) {
|
|
24
|
+
return `1. Halbjahr ${startYear}`;
|
|
25
|
+
}
|
|
26
|
+
// 2. Halbjahr: 01.07 - 31.12
|
|
27
|
+
if (startDate.month() === 6 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31) {
|
|
28
|
+
return `2. Halbjahr ${startYear}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Quartal
|
|
33
|
+
if (startYear === endYear) {
|
|
34
|
+
// Q1: 01.01 - 31.03
|
|
35
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 2 && endDate.date() === 31) {
|
|
36
|
+
return `Q1 ${startYear}`;
|
|
37
|
+
}
|
|
38
|
+
// Q2: 01.04 - 30.06
|
|
39
|
+
if (startDate.month() === 3 && startDate.date() === 1 && endDate.month() === 5 && endDate.date() === 30) {
|
|
40
|
+
return `Q2 ${startYear}`;
|
|
41
|
+
}
|
|
42
|
+
// Q3: 01.07 - 30.09
|
|
43
|
+
if (startDate.month() === 6 && startDate.date() === 1 && endDate.month() === 8 && endDate.date() === 30) {
|
|
44
|
+
return `Q3 ${startYear}`;
|
|
45
|
+
}
|
|
46
|
+
// Q4: 01.10 - 31.12
|
|
47
|
+
if (startDate.month() === 9 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31) {
|
|
48
|
+
return `Q4 ${startYear}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Monat
|
|
53
|
+
if (startYear === endYear && startDate.month() === endDate.month()) {
|
|
54
|
+
if (startDate.date() === 1) {
|
|
55
|
+
const lastDay = startDate.clone().endOf("month").date();
|
|
56
|
+
if (endDate.date() === lastDay) {
|
|
57
|
+
const months = [
|
|
58
|
+
"Januar",
|
|
59
|
+
"Februar",
|
|
60
|
+
"März",
|
|
61
|
+
"April",
|
|
62
|
+
"Mai",
|
|
63
|
+
"Juni",
|
|
64
|
+
"Juli",
|
|
65
|
+
"August",
|
|
66
|
+
"September",
|
|
67
|
+
"Oktober",
|
|
68
|
+
"November",
|
|
69
|
+
"Dezember",
|
|
70
|
+
];
|
|
71
|
+
return `${months[startDate.month()]} ${startYear}`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Kalenderwoche (KW)
|
|
77
|
+
const diffDays = endDate.diff(startDate, "days");
|
|
78
|
+
if (
|
|
79
|
+
diffDays === 6 &&
|
|
80
|
+
startDate.day() === 1 && // Montag
|
|
81
|
+
endDate.day() === 0 // Sonntag
|
|
82
|
+
) {
|
|
83
|
+
const weekNumber = startDate.isoWeek();
|
|
84
|
+
return `KW-${weekNumber} ${startYear}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Standard
|
|
88
|
+
return `${startDate.format("DD.MM.YYYY")} - ${endDate.format("DD.MM.YYYY")}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const DateFunctions = new DateFunctionsFacade();
|