@f-o-t/datetime 0.1.0
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/CHANGELOG.md +13 -0
- package/README.md +726 -0
- package/biome.json +39 -0
- package/bunup.config.ts +14 -0
- package/examples/plugins-demo.ts +85 -0
- package/fot.config.ts +5 -0
- package/package.json +47 -0
- package/src/core/datetime.test.ts +1498 -0
- package/src/core/datetime.ts +694 -0
- package/src/core/factory.test.ts +167 -0
- package/src/core/factory.ts +32 -0
- package/src/errors.ts +82 -0
- package/src/index.ts +20 -0
- package/src/plugins/business-days/business-days.test.ts +225 -0
- package/src/plugins/business-days/index.ts +126 -0
- package/src/plugins/format/format.test.ts +173 -0
- package/src/plugins/format/index.ts +78 -0
- package/src/plugins/format/tokens.ts +153 -0
- package/src/plugins/index.ts +15 -0
- package/src/plugins/plugin-base.test.ts +211 -0
- package/src/plugins/plugin-base.ts +104 -0
- package/src/plugins/relative-time/index.ts +169 -0
- package/src/plugins/relative-time/relative-time.test.ts +164 -0
- package/src/plugins/timezone/index.ts +152 -0
- package/src/plugins/timezone/timezone.test.ts +135 -0
- package/src/schemas.test.ts +283 -0
- package/src/schemas.ts +104 -0
- package/src/types.ts +122 -0
- package/tsconfig.json +29 -0
package/biome.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true,
|
|
7
|
+
"defaultBranch": "main"
|
|
8
|
+
},
|
|
9
|
+
"files": {
|
|
10
|
+
"ignoreUnknown": false,
|
|
11
|
+
"ignore": [
|
|
12
|
+
"node_modules",
|
|
13
|
+
"dist",
|
|
14
|
+
"*.config.ts"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"formatter": {
|
|
18
|
+
"enabled": true,
|
|
19
|
+
"indentStyle": "tab",
|
|
20
|
+
"indentWidth": 2,
|
|
21
|
+
"lineWidth": 80
|
|
22
|
+
},
|
|
23
|
+
"organizeImports": {
|
|
24
|
+
"enabled": true
|
|
25
|
+
},
|
|
26
|
+
"linter": {
|
|
27
|
+
"enabled": true,
|
|
28
|
+
"rules": {
|
|
29
|
+
"recommended": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"javascript": {
|
|
33
|
+
"formatter": {
|
|
34
|
+
"quoteStyle": "double",
|
|
35
|
+
"semicolons": "always",
|
|
36
|
+
"trailingCommas": "all"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
package/bunup.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineConfig } from "bunup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
dts: {
|
|
5
|
+
inferTypes: true,
|
|
6
|
+
},
|
|
7
|
+
entry: [
|
|
8
|
+
"src/index.ts",
|
|
9
|
+
"src/plugins/timezone/index.ts",
|
|
10
|
+
"src/plugins/business-days/index.ts",
|
|
11
|
+
"src/plugins/format/index.ts",
|
|
12
|
+
"src/plugins/relative-time/index.ts",
|
|
13
|
+
],
|
|
14
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo script showing all four core plugins in action
|
|
3
|
+
*/
|
|
4
|
+
import { DateTime } from "../src/core/datetime";
|
|
5
|
+
import {
|
|
6
|
+
businessDaysPlugin,
|
|
7
|
+
formatPlugin,
|
|
8
|
+
relativeTimePlugin,
|
|
9
|
+
timezonePlugin,
|
|
10
|
+
} from "../src/plugins/index";
|
|
11
|
+
|
|
12
|
+
// Install all plugins
|
|
13
|
+
DateTime.extend(timezonePlugin);
|
|
14
|
+
DateTime.extend(businessDaysPlugin);
|
|
15
|
+
DateTime.extend(formatPlugin);
|
|
16
|
+
DateTime.extend(relativeTimePlugin);
|
|
17
|
+
|
|
18
|
+
console.log("🎉 DateTime Plugin Demo\n");
|
|
19
|
+
|
|
20
|
+
// Create a DateTime instance
|
|
21
|
+
const dt = new DateTime("2024-01-15T14:30:45.123Z");
|
|
22
|
+
console.log("Base DateTime:", dt.toISO());
|
|
23
|
+
console.log();
|
|
24
|
+
|
|
25
|
+
// 1. Timezone Plugin
|
|
26
|
+
console.log("📍 Timezone Plugin:");
|
|
27
|
+
console.log(" Current timezone:", (dt as any).getTimezone());
|
|
28
|
+
const nyTime = (dt as any).tz("America/New_York");
|
|
29
|
+
console.log(" New York time:", (nyTime as any).getTimezone());
|
|
30
|
+
const utcTime = (nyTime as any).utc();
|
|
31
|
+
console.log(" Back to UTC:", (utcTime as any).getTimezone());
|
|
32
|
+
console.log();
|
|
33
|
+
|
|
34
|
+
// 2. Business Days Plugin
|
|
35
|
+
console.log("💼 Business Days Plugin:");
|
|
36
|
+
const monday = new DateTime("2024-01-15T12:00:00.000Z"); // Monday
|
|
37
|
+
console.log(" Is Monday a weekday?", (monday as any).isWeekday());
|
|
38
|
+
const saturday = new DateTime("2024-01-20T12:00:00.000Z"); // Saturday
|
|
39
|
+
console.log(" Is Saturday a weekday?", (saturday as any).isWeekday());
|
|
40
|
+
const plusThreeDays = (monday as any).addBusinessDays(3);
|
|
41
|
+
console.log(
|
|
42
|
+
" Monday + 3 business days:",
|
|
43
|
+
(plusThreeDays as any).format("dddd, MMMM D"),
|
|
44
|
+
);
|
|
45
|
+
console.log();
|
|
46
|
+
|
|
47
|
+
// 3. Format Plugin
|
|
48
|
+
console.log("🎨 Format Plugin:");
|
|
49
|
+
console.log(" ISO format:", dt.toISO());
|
|
50
|
+
console.log(" Custom format (YYYY-MM-DD):", (dt as any).format("YYYY-MM-DD"));
|
|
51
|
+
console.log(" Custom format (MM/DD/YYYY):", (dt as any).format("MM/DD/YYYY"));
|
|
52
|
+
console.log(
|
|
53
|
+
" Custom format (MMMM D, YYYY):",
|
|
54
|
+
(dt as any).format("MMMM D, YYYY"),
|
|
55
|
+
);
|
|
56
|
+
console.log(" Custom format (h:mm A):", (dt as any).format("h:mm A"));
|
|
57
|
+
console.log(
|
|
58
|
+
" Custom format (dddd, MMMM D, YYYY [at] h:mm A):",
|
|
59
|
+
(dt as any).format("dddd, MMMM D, YYYY [at] h:mm A"),
|
|
60
|
+
);
|
|
61
|
+
console.log();
|
|
62
|
+
|
|
63
|
+
// 4. Relative Time Plugin
|
|
64
|
+
console.log("⏰ Relative Time Plugin:");
|
|
65
|
+
const now = new DateTime();
|
|
66
|
+
const hourAgo = now.subtractHours(1);
|
|
67
|
+
const tomorrow = now.addDays(1);
|
|
68
|
+
const lastWeek = now.subtractDays(7);
|
|
69
|
+
|
|
70
|
+
console.log(" 1 hour ago from now:", (hourAgo as any).fromNow());
|
|
71
|
+
console.log(" Tomorrow from now:", (tomorrow as any).fromNow());
|
|
72
|
+
console.log(" Last week from now:", (lastWeek as any).fromNow());
|
|
73
|
+
console.log();
|
|
74
|
+
|
|
75
|
+
// Chaining plugins together
|
|
76
|
+
console.log("🔗 Chaining Plugins:");
|
|
77
|
+
const chained = new DateTime("2024-01-15T12:00:00.000Z");
|
|
78
|
+
const result = (chained as any)
|
|
79
|
+
.addBusinessDays(5)
|
|
80
|
+
.tz("America/New_York")
|
|
81
|
+
.format("dddd, MMMM D, YYYY [at] h:mm A");
|
|
82
|
+
console.log(" Monday + 5 business days in NY:", result);
|
|
83
|
+
console.log();
|
|
84
|
+
|
|
85
|
+
console.log("✅ All plugins working perfectly!");
|
package/fot.config.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@f-o-t/datetime",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./plugins/timezone": {
|
|
13
|
+
"types": "./dist/plugins/timezone/index.d.ts",
|
|
14
|
+
"default": "./dist/plugins/timezone/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./plugins/business-days": {
|
|
17
|
+
"types": "./dist/plugins/business-days/index.d.ts",
|
|
18
|
+
"default": "./dist/plugins/business-days/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./plugins/format": {
|
|
21
|
+
"types": "./dist/plugins/format/index.d.ts",
|
|
22
|
+
"default": "./dist/plugins/format/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./plugins/relative-time": {
|
|
25
|
+
"types": "./dist/plugins/relative-time/index.d.ts",
|
|
26
|
+
"default": "./dist/plugins/relative-time/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "bunup",
|
|
31
|
+
"dev": "bunup --watch",
|
|
32
|
+
"test": "bun test",
|
|
33
|
+
"test:coverage": "bun test --coverage",
|
|
34
|
+
"test:watch": "bun test --watch",
|
|
35
|
+
"typecheck": "tsc",
|
|
36
|
+
"check": "biome check --write ."
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@f-o-t/cli": "workspace:*",
|
|
40
|
+
"@f-o-t/config": "workspace:*"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/F-O-T/libraries.git",
|
|
45
|
+
"directory": "libraries/datetime"
|
|
46
|
+
}
|
|
47
|
+
}
|