mclocks-datetime-util 0.0.3 → 0.0.5
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 +2 -1
- package/package.json +2 -1
- package/server.js +26 -1
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ An MCP (Model Context Protocol) server that gives AI assistants the ability to a
|
|
|
9
9
|
| Tool | Description |
|
|
10
10
|
|------|-------------|
|
|
11
11
|
| **`current-time`** | Get the current time in your configured timezones |
|
|
12
|
+
| **`local-time`** | Get the current local time in the user's timezone (from `convtz` config or system default). Useful when other MCP tools or prompts need the user's local date/time |
|
|
12
13
|
| **`convert-time`** | Convert a datetime string or epoch timestamp to multiple timezones |
|
|
13
14
|
| **`next-weekday`** | Find the date of the next occurrence of a given weekday |
|
|
14
15
|
| **`date-to-weekday`** | Get the day of the week for a given date |
|
|
@@ -54,7 +55,7 @@ If you use the [mclocks](https://github.com/bayashi/mclocks) desktop app, the MC
|
|
|
54
55
|
|
|
55
56
|
- **`clocks`** — Timezones from your clocks become default conversion targets
|
|
56
57
|
- **`convtz`** — Default source timezone for datetime strings without timezone info
|
|
57
|
-
- **`usetz`** —
|
|
58
|
+
- **`usetz`** — Enables strict timezone conversion for historically accurate UTC offsets (e.g. JST was +09:18 before 1888)
|
|
58
59
|
- **`locale`** — Language for weekday names (e.g. `ja`, `pt`, `de`)
|
|
59
60
|
|
|
60
61
|
Config file locations:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mclocks-datetime-util",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "MCP server for datetime and timezone conversion, powered by mclocks config",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
26
26
|
"cdate": "0.0.7",
|
|
27
|
+
"jsonc-parser": "^3.3.1",
|
|
27
28
|
"zod": "^4.3.6"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
package/server.js
CHANGED
|
@@ -4,6 +4,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { cdate } from "cdate";
|
|
7
|
+
import { parse as parseJsonc } from "jsonc-parser";
|
|
7
8
|
import { readFileSync } from "fs";
|
|
8
9
|
import { join } from "path";
|
|
9
10
|
|
|
@@ -76,7 +77,12 @@ function loadMclocksConfig() {
|
|
|
76
77
|
}
|
|
77
78
|
try {
|
|
78
79
|
const raw = readFileSync(configPath, "utf-8");
|
|
79
|
-
|
|
80
|
+
const errors = [];
|
|
81
|
+
const parsed = parseJsonc(raw, errors, { allowTrailingComma: true });
|
|
82
|
+
if (errors.length > 0 || parsed === null || typeof parsed !== "object") {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return parsed;
|
|
80
86
|
} catch {
|
|
81
87
|
return null;
|
|
82
88
|
}
|
|
@@ -125,6 +131,8 @@ function convertToTimezone(cdt, src, tz, usetz) {
|
|
|
125
131
|
try {
|
|
126
132
|
let result;
|
|
127
133
|
if (usetz) {
|
|
134
|
+
// Use strict timezone conversion for historically accurate UTC offsets.
|
|
135
|
+
// For example, before 1888/1/1 00:00:00 in JST, its utcOffset is 09:18.
|
|
128
136
|
result = cdt(src).tz(tz).text();
|
|
129
137
|
} else {
|
|
130
138
|
const offset = cdt().tz(tz).utcOffset();
|
|
@@ -265,6 +273,23 @@ server.tool(
|
|
|
265
273
|
}
|
|
266
274
|
);
|
|
267
275
|
|
|
276
|
+
server.tool(
|
|
277
|
+
"local-time",
|
|
278
|
+
"Get the current local time in the user's timezone (from convtz config or system default). Use this when other MCP tools or prompts need the user's local date/time.",
|
|
279
|
+
{},
|
|
280
|
+
async () => {
|
|
281
|
+
const tz = configConvTZ || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
282
|
+
const source = configConvTZ ? "config (convtz)" : "system";
|
|
283
|
+
const now = new Date();
|
|
284
|
+
const cdt = cdate().cdateFn();
|
|
285
|
+
const offset = cdt().tz(tz).utcOffset();
|
|
286
|
+
const result = cdt(now).utcOffset(offset).text();
|
|
287
|
+
return {
|
|
288
|
+
content: [{ type: "text", text: `${result} in ${tz} (source: ${source})` }],
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
);
|
|
292
|
+
|
|
268
293
|
server.tool(
|
|
269
294
|
"next-weekday",
|
|
270
295
|
"Find the date of the next occurrence of a given weekday from today.",
|