tpmjs-datetime-tools 1.0.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/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # DateTime Tools for TPMJS
2
+
3
+ TPMJS tools for getting current date and time in various formats and timezones.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @lmwat/datetime-tools
9
+ ```
10
+
11
+ ## Tools
12
+
13
+ ### getCurrentDateTime
14
+
15
+ Gets the current date and time in various formats and timezones.
16
+
17
+ **Parameters:**
18
+ - `timezone` (optional): Timezone string (e.g., "America/New_York", "Europe/London", "Asia/Tokyo", "UTC"). Defaults to system timezone.
19
+ - `format` (optional): Output format:
20
+ - `"iso"`: ISO 8601 format (default)
21
+ - `"locale"`: Localized string format
22
+ - `"unix"`: Unix timestamp (seconds since epoch)
23
+ - `"custom"`: Detailed breakdown with date components
24
+ - `includeOffset` (optional): Include timezone offset in response (default: false)
25
+
26
+ **Returns:**
27
+ - `success`: Boolean indicating if the operation was successful
28
+ - `datetime`: The formatted date/time string
29
+ - `timestamp`: JavaScript timestamp (milliseconds since epoch)
30
+ - `unixTimestamp`: Unix timestamp (seconds since epoch)
31
+ - `timezone`: The timezone used
32
+ - `offset`: Timezone offset (if includeOffset is true)
33
+ - `components`: Detailed date components (only when format is "custom")
34
+
35
+ **Example Usage:**
36
+
37
+ ```typescript
38
+ import { getCurrentDateTime } from '@lmwat/datetime-tools';
39
+
40
+ // Get current time in ISO format
41
+ const result1 = await getCurrentDateTime.execute({});
42
+ // Returns: { success: true, datetime: "2026-02-13T10:30:00.000Z", ... }
43
+
44
+ // Get current time in New York timezone
45
+ const result2 = await getCurrentDateTime.execute({
46
+ timezone: 'America/New_York',
47
+ format: 'locale'
48
+ });
49
+ // Returns: { success: true, datetime: "2/13/2026, 5:30:00 AM", ... }
50
+
51
+ // Get detailed breakdown with timezone offset
52
+ const result3 = await getCurrentDateTime.execute({
53
+ format: 'custom',
54
+ includeOffset: true
55
+ });
56
+ // Returns detailed components including year, month, day, hour, etc.
57
+ ```
58
+
59
+ ## Publishing to TPMJS
60
+
61
+ This tool is designed to be published to [TPMJS](https://tpmjs.com), where it will be automatically indexed and made available for AI agents to use.
62
+
63
+ After publishing to npm, your tool will appear on tpmjs.com within 15 minutes.
64
+
65
+ ## License
66
+
67
+ MIT
@@ -0,0 +1,24 @@
1
+ import * as ai from 'ai';
2
+ import { z } from 'zod';
3
+
4
+ declare const getCurrentDateTime: ai.Tool<z.ZodObject<{
5
+ timezone: z.ZodOptional<z.ZodString>;
6
+ format: z.ZodDefault<z.ZodEnum<["iso", "locale", "unix", "custom"]>>;
7
+ includeOffset: z.ZodDefault<z.ZodBoolean>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ format: "iso" | "locale" | "unix" | "custom";
10
+ includeOffset: boolean;
11
+ timezone?: string | undefined;
12
+ }, {
13
+ timezone?: string | undefined;
14
+ format?: "iso" | "locale" | "unix" | "custom" | undefined;
15
+ includeOffset?: boolean | undefined;
16
+ }>, any> & {
17
+ execute: (args: {
18
+ format: "iso" | "locale" | "unix" | "custom";
19
+ includeOffset: boolean;
20
+ timezone?: string | undefined;
21
+ }, options: ai.ToolExecutionOptions) => PromiseLike<any>;
22
+ };
23
+
24
+ export { getCurrentDateTime };
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ // src/tools/getCurrentDateTime.ts
2
+ import { tool } from "ai";
3
+ import { z } from "zod";
4
+ var GetCurrentDateTimeSchema = z.object({
5
+ timezone: z.string().optional().describe('Optional timezone (e.g., "America/New_York", "Europe/London", "Asia/Tokyo", "UTC"). Defaults to system timezone.'),
6
+ format: z.enum(["iso", "locale", "unix", "custom"]).default("iso").describe('Output format: "iso" for ISO 8601, "locale" for localized string, "unix" for Unix timestamp, "custom" for detailed breakdown'),
7
+ includeOffset: z.boolean().default(false).describe("Include timezone offset in the response")
8
+ });
9
+ var getCurrentDateTime = tool({
10
+ description: "Gets the current date and time in various formats and timezones. Supports ISO 8601, localized strings, Unix timestamps, and detailed date components.",
11
+ parameters: GetCurrentDateTimeSchema,
12
+ async execute(input) {
13
+ if (input.format && !["iso", "locale", "unix", "custom"].includes(input.format)) {
14
+ return {
15
+ success: false,
16
+ error: "Invalid format specified",
17
+ message: "Format must be one of: iso, locale, unix, custom"
18
+ };
19
+ }
20
+ try {
21
+ const now = /* @__PURE__ */ new Date();
22
+ let formattedDate;
23
+ let offset;
24
+ if (input.includeOffset || input.format === "custom") {
25
+ const offsetMinutes = -now.getTimezoneOffset();
26
+ const offsetHours = Math.floor(Math.abs(offsetMinutes) / 60);
27
+ const offsetMins = Math.abs(offsetMinutes) % 60;
28
+ const sign = offsetMinutes >= 0 ? "+" : "-";
29
+ offset = `${sign}${String(offsetHours).padStart(2, "0")}:${String(offsetMins).padStart(2, "0")}`;
30
+ }
31
+ switch (input.format) {
32
+ case "iso":
33
+ formattedDate = input.timezone ? new Date(now.toLocaleString("en-US", { timeZone: input.timezone })).toISOString() : now.toISOString();
34
+ break;
35
+ case "locale":
36
+ formattedDate = input.timezone ? now.toLocaleString("en-US", { timeZone: input.timezone }) : now.toLocaleString();
37
+ break;
38
+ case "unix":
39
+ formattedDate = Math.floor(now.getTime() / 1e3).toString();
40
+ break;
41
+ case "custom":
42
+ const dateInTz = input.timezone ? new Date(now.toLocaleString("en-US", { timeZone: input.timezone })) : now;
43
+ return {
44
+ success: true,
45
+ datetime: dateInTz.toISOString(),
46
+ components: {
47
+ year: dateInTz.getFullYear(),
48
+ month: dateInTz.getMonth() + 1,
49
+ day: dateInTz.getDate(),
50
+ hour: dateInTz.getHours(),
51
+ minute: dateInTz.getMinutes(),
52
+ second: dateInTz.getSeconds(),
53
+ millisecond: dateInTz.getMilliseconds(),
54
+ dayOfWeek: dateInTz.toLocaleDateString("en-US", { weekday: "long" }),
55
+ monthName: dateInTz.toLocaleDateString("en-US", { month: "long" })
56
+ },
57
+ timestamp: now.getTime(),
58
+ unixTimestamp: Math.floor(now.getTime() / 1e3),
59
+ timezone: input.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,
60
+ offset
61
+ };
62
+ default:
63
+ formattedDate = now.toISOString();
64
+ }
65
+ const response = {
66
+ success: true,
67
+ datetime: formattedDate,
68
+ timestamp: now.getTime(),
69
+ unixTimestamp: Math.floor(now.getTime() / 1e3),
70
+ timezone: input.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone
71
+ };
72
+ if (input.includeOffset && offset) {
73
+ response.offset = offset;
74
+ }
75
+ return response;
76
+ } catch (error) {
77
+ return {
78
+ success: false,
79
+ error: "Failed to get current date/time",
80
+ message: error instanceof Error ? error.message : "Unknown error occurred"
81
+ };
82
+ }
83
+ }
84
+ });
85
+ export {
86
+ getCurrentDateTime
87
+ };
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tools/getCurrentDateTime.ts"],"sourcesContent":["import { tool } from 'ai';\nimport { z } from 'zod';\n\nconst GetCurrentDateTimeSchema = z.object({\n timezone: z.string()\n .optional()\n .describe('Optional timezone (e.g., \"America/New_York\", \"Europe/London\", \"Asia/Tokyo\", \"UTC\"). Defaults to system timezone.'),\n format: z.enum(['iso', 'locale', 'unix', 'custom'])\n .default('iso')\n .describe('Output format: \"iso\" for ISO 8601, \"locale\" for localized string, \"unix\" for Unix timestamp, \"custom\" for detailed breakdown'),\n includeOffset: z.boolean()\n .default(false)\n .describe('Include timezone offset in the response'),\n});\n\nexport const getCurrentDateTime = tool({\n description: 'Gets the current date and time in various formats and timezones. Supports ISO 8601, localized strings, Unix timestamps, and detailed date components.',\n parameters: GetCurrentDateTimeSchema,\n async execute(input) {\n // Defensive parameter validation\n if (input.format && !['iso', 'locale', 'unix', 'custom'].includes(input.format)) {\n return {\n success: false,\n error: 'Invalid format specified',\n message: 'Format must be one of: iso, locale, unix, custom',\n };\n }\n\n try {\n const now = new Date();\n let formattedDate: string;\n let offset: string | undefined;\n\n // Calculate timezone offset if requested\n if (input.includeOffset || input.format === 'custom') {\n const offsetMinutes = -now.getTimezoneOffset();\n const offsetHours = Math.floor(Math.abs(offsetMinutes) / 60);\n const offsetMins = Math.abs(offsetMinutes) % 60;\n const sign = offsetMinutes >= 0 ? '+' : '-';\n offset = `${sign}${String(offsetHours).padStart(2, '0')}:${String(offsetMins).padStart(2, '0')}`;\n }\n\n switch (input.format) {\n case 'iso':\n formattedDate = input.timezone\n ? new Date(now.toLocaleString('en-US', { timeZone: input.timezone })).toISOString()\n : now.toISOString();\n break;\n\n case 'locale':\n formattedDate = input.timezone\n ? now.toLocaleString('en-US', { timeZone: input.timezone })\n : now.toLocaleString();\n break;\n\n case 'unix':\n formattedDate = Math.floor(now.getTime() / 1000).toString();\n break;\n\n case 'custom':\n const dateInTz = input.timezone\n ? new Date(now.toLocaleString('en-US', { timeZone: input.timezone }))\n : now;\n\n return {\n success: true,\n datetime: dateInTz.toISOString(),\n components: {\n year: dateInTz.getFullYear(),\n month: dateInTz.getMonth() + 1,\n day: dateInTz.getDate(),\n hour: dateInTz.getHours(),\n minute: dateInTz.getMinutes(),\n second: dateInTz.getSeconds(),\n millisecond: dateInTz.getMilliseconds(),\n dayOfWeek: dateInTz.toLocaleDateString('en-US', { weekday: 'long' }),\n monthName: dateInTz.toLocaleDateString('en-US', { month: 'long' }),\n },\n timestamp: now.getTime(),\n unixTimestamp: Math.floor(now.getTime() / 1000),\n timezone: input.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,\n offset: offset,\n };\n\n default:\n formattedDate = now.toISOString();\n }\n\n const response: any = {\n success: true,\n datetime: formattedDate,\n timestamp: now.getTime(),\n unixTimestamp: Math.floor(now.getTime() / 1000),\n timezone: input.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,\n };\n\n if (input.includeOffset && offset) {\n response.offset = offset;\n }\n\n return response;\n } catch (error) {\n return {\n success: false,\n error: 'Failed to get current date/time',\n message: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n },\n});\n"],"mappings":";AA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AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO;AAAA,QACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "tpmjs-datetime-tools",
3
+ "version": "1.0.0",
4
+ "description": "TPMJS tools for getting current date and time in various formats and timezones",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "build": "tsup",
10
+ "type-check": "tsc --noEmit",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "keywords": [
14
+ "tpmjs",
15
+ "datetime",
16
+ "time",
17
+ "date",
18
+ "utilities",
19
+ "timezone"
20
+ ],
21
+ "tpmjs": {
22
+ "category": "utilities",
23
+ "tools": [
24
+ {
25
+ "name": "getCurrentDateTime",
26
+ "description": "Gets the current date and time in various formats and timezones"
27
+ }
28
+ ]
29
+ },
30
+ "author": "lmwat",
31
+ "license": "MIT",
32
+ "dependencies": {
33
+ "ai": "^4.0.0",
34
+ "zod": "^3.22.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^20.0.0",
38
+ "tsup": "^8.0.0",
39
+ "typescript": "^5.3.0"
40
+ }
41
+ }