@f-o-t/datetime 0.1.0 → 0.1.4
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/core/datetime.d.ts +341 -0
- package/dist/core/datetime.d.ts.map +1 -0
- package/{src/core/factory.ts → dist/core/factory.d.ts} +2 -4
- package/dist/core/factory.d.ts.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index-77f5wgyc.js +41 -0
- package/dist/index-77f5wgyc.js.map +10 -0
- package/dist/index-9jdtsp4s.js +55 -0
- package/dist/index-9jdtsp4s.js.map +10 -0
- package/dist/index-a78jd9k6.js +64 -0
- package/dist/index-a78jd9k6.js.map +10 -0
- package/dist/index-rtm7bpky.js +86 -0
- package/dist/index-rtm7bpky.js.map +10 -0
- package/dist/index-v3cytzbp.js +105 -0
- package/dist/index-v3cytzbp.js.map +11 -0
- package/{src/index.ts → dist/index.d.ts} +2 -15
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +390 -0
- package/dist/index.js.map +13 -0
- package/dist/plugins/business-days/index.d.ts +45 -0
- package/dist/plugins/business-days/index.d.ts.map +1 -0
- package/dist/plugins/business-days/index.js +10 -0
- package/dist/plugins/business-days/index.js.map +9 -0
- package/dist/plugins/format/index.d.ts +54 -0
- package/dist/plugins/format/index.d.ts.map +1 -0
- package/dist/plugins/format/index.js +10 -0
- package/dist/plugins/format/index.js.map +9 -0
- package/dist/plugins/format/tokens.d.ts +20 -0
- package/dist/plugins/format/tokens.d.ts.map +1 -0
- package/{src/plugins/index.ts → dist/plugins/index.d.ts} +1 -2
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/plugin-base.d.ts +49 -0
- package/dist/plugins/plugin-base.d.ts.map +1 -0
- package/dist/plugins/relative-time/index.d.ts +61 -0
- package/dist/plugins/relative-time/index.d.ts.map +1 -0
- package/dist/plugins/relative-time/index.js +10 -0
- package/dist/plugins/relative-time/index.js.map +9 -0
- package/dist/plugins/timezone/index.d.ts +59 -0
- package/dist/plugins/timezone/index.d.ts.map +1 -0
- package/dist/plugins/timezone/index.js +10 -0
- package/dist/plugins/timezone/index.js.map +9 -0
- package/dist/schemas.d.ts +66 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/types.d.ts +96 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +50 -45
- package/CHANGELOG.md +0 -13
- package/biome.json +0 -39
- package/bunup.config.ts +0 -14
- package/examples/plugins-demo.ts +0 -85
- package/fot.config.ts +0 -5
- package/src/core/datetime.test.ts +0 -1498
- package/src/core/datetime.ts +0 -694
- package/src/core/factory.test.ts +0 -167
- package/src/errors.ts +0 -82
- package/src/plugins/business-days/business-days.test.ts +0 -225
- package/src/plugins/business-days/index.ts +0 -126
- package/src/plugins/format/format.test.ts +0 -173
- package/src/plugins/format/index.ts +0 -78
- package/src/plugins/format/tokens.ts +0 -153
- package/src/plugins/plugin-base.test.ts +0 -211
- package/src/plugins/plugin-base.ts +0 -104
- package/src/plugins/relative-time/index.ts +0 -169
- package/src/plugins/relative-time/relative-time.test.ts +0 -164
- package/src/plugins/timezone/index.ts +0 -152
- package/src/plugins/timezone/timezone.test.ts +0 -135
- package/src/schemas.test.ts +0 -283
- package/src/schemas.ts +0 -104
- package/src/types.ts +0 -122
- package/tsconfig.json +0 -29
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { DateTime as DateTimeInstance } from "./core/datetime";
|
|
2
|
+
/**
|
|
3
|
+
* Time units supported by the library
|
|
4
|
+
*/
|
|
5
|
+
export type TimeUnit = "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year";
|
|
6
|
+
/**
|
|
7
|
+
* DateTime instance type - re-exported from the class
|
|
8
|
+
*/
|
|
9
|
+
export type DateTime = DateTimeInstance;
|
|
10
|
+
/**
|
|
11
|
+
* Input types that can be converted to DateTime
|
|
12
|
+
*/
|
|
13
|
+
export type DateInput = Date | string | number | DateTime;
|
|
14
|
+
/**
|
|
15
|
+
* DateTime class type (used for plugin typing)
|
|
16
|
+
* Must be defined before DateTimePlugin to avoid forward reference
|
|
17
|
+
*/
|
|
18
|
+
export interface DateTimeClass {
|
|
19
|
+
new (input?: DateInput): DateTime;
|
|
20
|
+
prototype: DateTime;
|
|
21
|
+
extend: (plugin: DateTimePlugin, options?: Record<string, unknown>) => void;
|
|
22
|
+
hasPlugin: (name: string) => boolean;
|
|
23
|
+
getPlugin: (name: string) => DateTimePlugin | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Plugin definition
|
|
27
|
+
*/
|
|
28
|
+
export interface DateTimePlugin {
|
|
29
|
+
/**
|
|
30
|
+
* Plugin name (must be unique)
|
|
31
|
+
*/
|
|
32
|
+
name: string;
|
|
33
|
+
/**
|
|
34
|
+
* Install function that extends the DateTime class
|
|
35
|
+
* @param DateTimeClass - The DateTime class to extend
|
|
36
|
+
* @param options - Optional plugin configuration
|
|
37
|
+
*/
|
|
38
|
+
install: (DateTimeClass: DateTimeClass, options?: Record<string, unknown>) => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Configuration options for DateTime instance creation
|
|
42
|
+
*/
|
|
43
|
+
export interface DateTimeConfig {
|
|
44
|
+
/**
|
|
45
|
+
* Timezone (IANA timezone string, e.g., "America/New_York")
|
|
46
|
+
* Defaults to system timezone
|
|
47
|
+
*/
|
|
48
|
+
timezone?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Locale for formatting (BCP 47 language tag, e.g., "en-US")
|
|
51
|
+
* Defaults to system locale
|
|
52
|
+
*/
|
|
53
|
+
locale?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to use UTC mode
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
utc?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Whether parsing should be strict
|
|
61
|
+
* @default true
|
|
62
|
+
*/
|
|
63
|
+
strict?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Options for formatting dates
|
|
67
|
+
*/
|
|
68
|
+
export interface FormatOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Locale for formatting (BCP 47 language tag)
|
|
71
|
+
*/
|
|
72
|
+
locale?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Timezone for formatting (IANA timezone string)
|
|
75
|
+
*/
|
|
76
|
+
timezone?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Options for parsing dates
|
|
80
|
+
*/
|
|
81
|
+
export interface ParseOptions {
|
|
82
|
+
/**
|
|
83
|
+
* Whether to use strict parsing
|
|
84
|
+
* @default true
|
|
85
|
+
*/
|
|
86
|
+
strict?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Expected format string
|
|
89
|
+
*/
|
|
90
|
+
format?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Timezone to parse in (IANA timezone string)
|
|
93
|
+
*/
|
|
94
|
+
timezone?: string;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,QAAQ,GACf,aAAa,GACb,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,KAAK,GACL,MAAM,GACN,OAAO,GACP,MAAM,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,gBAAgB,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC3B,KAAK,KAAK,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAClC,SAAS,EAAE,Q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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
2
|
+
"name": "@f-o-t/datetime",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./plugins/timezone": {
|
|
16
|
+
"types": "./dist/plugins/timezone/index.d.ts",
|
|
17
|
+
"default": "./dist/plugins/timezone/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./plugins/business-days": {
|
|
20
|
+
"types": "./dist/plugins/business-days/index.d.ts",
|
|
21
|
+
"default": "./dist/plugins/business-days/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./plugins/format": {
|
|
24
|
+
"types": "./dist/plugins/format/index.d.ts",
|
|
25
|
+
"default": "./dist/plugins/format/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./plugins/relative-time": {
|
|
28
|
+
"types": "./dist/plugins/relative-time/index.d.ts",
|
|
29
|
+
"default": "./dist/plugins/relative-time/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "bun x --bun fot build",
|
|
34
|
+
"test": "bun x --bun fot test",
|
|
35
|
+
"lint": "bun x --bun fot lint",
|
|
36
|
+
"format": "bun x --bun fot format",
|
|
37
|
+
"typecheck": "bun x --bun fot typecheck"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"zod": "^4.3.6"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@f-o-t/cli": "^1.0.0",
|
|
44
|
+
"@f-o-t/config": "^1.0.0",
|
|
45
|
+
"@types/bun": "latest"
|
|
46
|
+
},
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/F-O-T/libraries.git",
|
|
50
|
+
"directory": "libraries/datetime"
|
|
51
|
+
}
|
|
47
52
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 0.1.0
|
|
4
|
-
|
|
5
|
-
### Features
|
|
6
|
-
|
|
7
|
-
- `DateTime` class with core datetime functionality
|
|
8
|
-
- `datetime()` factory function for creating DateTime instances
|
|
9
|
-
- Plugin system with `createPlugin()`, `isPlugin()`, and `isValidPluginName()`
|
|
10
|
-
- Date parsing and formatting with configurable options
|
|
11
|
-
- Error handling with `InvalidDateError` and `PluginError`
|
|
12
|
-
- Type definitions for DateInput, TimeUnit, FormatOptions, and ParseOptions
|
|
13
|
-
- DateInputSchema for validation
|
package/biome.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
});
|
package/examples/plugins-demo.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
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!");
|