mclocks-datetime-util 0.0.2 → 0.0.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/README.md +133 -0
- package/package.json +1 -1
- package/server.js +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# mclocks-datetime-util
|
|
2
|
+
|
|
3
|
+
An MCP (Model Context Protocol) server that gives AI assistants the ability to answer time/date questions across multiple timezones. It converts between datetime formats and epoch timestamps, calculates days between dates or days until a target date, supports flexible locale settings for weekday names in multiple languages, and integrates with the [mclocks](https://github.com/bayashi/mclocks) desktop clock app configuration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
7 tools for datetime operations:
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
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 |
|
|
13
|
+
| **`convert-time`** | Convert a datetime string or epoch timestamp to multiple timezones |
|
|
14
|
+
| **`next-weekday`** | Find the date of the next occurrence of a given weekday |
|
|
15
|
+
| **`date-to-weekday`** | Get the day of the week for a given date |
|
|
16
|
+
| **`days-until`** | Count the number of days from today until a specified date |
|
|
17
|
+
| **`days-between`** | Count the number of days between two dates |
|
|
18
|
+
| **`date-offset`** | Calculate the date N days before or after a given date |
|
|
19
|
+
|
|
20
|
+
### Highlights
|
|
21
|
+
|
|
22
|
+
- **Zero configuration** — works out of the box with sensible timezone defaults
|
|
23
|
+
- **mclocks integration** — automatically reads your mclocks `config.json` so the timezones you've set up are reflected in AI responses
|
|
24
|
+
- **Epoch conversion** — supports seconds, milliseconds, microseconds, and nanoseconds
|
|
25
|
+
- **Flexible input** — accepts ISO 8601, common date formats (e.g. `March 15, 2026`), and BigQuery-style datetime (`2024-01-01 12:00:00 UTC`)
|
|
26
|
+
- **Locale support** — weekday names in multiple languages via the `locale` setting
|
|
27
|
+
|
|
28
|
+
## Prerequisites
|
|
29
|
+
|
|
30
|
+
- [Node.js](https://nodejs.org/) v18 or later
|
|
31
|
+
|
|
32
|
+
## Setup
|
|
33
|
+
|
|
34
|
+
Add the following to your MCP configuration file and restart the application. The MCP server will be automatically downloaded and started.
|
|
35
|
+
|
|
36
|
+
- **Cursor**: `.cursor/mcp.json` in your project root, or global `~/.cursor/mcp.json`
|
|
37
|
+
- **Claude Desktop** (`claude_desktop_config.json`): [Windows] `%APPDATA%\Claude\`, [macOS] `~/Library/Application Support/Claude/`, [Linux] `~/.config/Claude/`
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"mclocks-datetime-util": {
|
|
43
|
+
"command": "npx",
|
|
44
|
+
"args": ["-y", "mclocks-datetime-util"]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
### Automatic mclocks config detection
|
|
53
|
+
|
|
54
|
+
If you use the [mclocks](https://github.com/bayashi/mclocks) desktop app, the MCP server automatically reads your `config.json` and uses:
|
|
55
|
+
|
|
56
|
+
- **`clocks`** — Timezones from your clocks become default conversion targets
|
|
57
|
+
- **`convtz`** — Default source timezone for datetime strings without timezone info
|
|
58
|
+
- **`usetz`** — Enables strict timezone conversion for historically accurate UTC offsets (e.g. JST was +09:18 before 1888)
|
|
59
|
+
- **`locale`** — Language for weekday names (e.g. `ja`, `pt`, `de`)
|
|
60
|
+
|
|
61
|
+
Config file locations:
|
|
62
|
+
|
|
63
|
+
- Windows: `C:\Users\{USER}\AppData\Roaming\com.bayashi.mclocks\config.json`
|
|
64
|
+
- macOS: `/Users/{USER}/Library/Application Support/com.bayashi.mclocks/config.json`
|
|
65
|
+
|
|
66
|
+
### Without mclocks
|
|
67
|
+
|
|
68
|
+
The server works perfectly fine without the mclocks app. When no config is found, it uses these default timezones:
|
|
69
|
+
|
|
70
|
+
`UTC`, `America/New_York`, `America/Los_Angeles`, `Europe/London`, `Europe/Berlin`, `Asia/Tokyo`, `Asia/Shanghai`, `Asia/Kolkata`, `Australia/Sydney`
|
|
71
|
+
|
|
72
|
+
### Environment variables
|
|
73
|
+
|
|
74
|
+
Override config settings (or configure without `config.json`) using environment variables. They take priority over `config.json` values.
|
|
75
|
+
|
|
76
|
+
| Variable | Description | Default |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `MCLOCKS_CONFIG_PATH` | Path to `config.json` (usually auto-detected) | auto-detect |
|
|
79
|
+
| `MCLOCKS_LOCALE` | Locale for weekday names (e.g. `ja`, `pt`, `de`) | `en` |
|
|
80
|
+
| `MCLOCKS_CONVTZ` | Default source timezone (e.g. `Asia/Tokyo`) | *(none)* |
|
|
81
|
+
| `MCLOCKS_USETZ` | Set to `true` for strict timezone conversion | `false` |
|
|
82
|
+
|
|
83
|
+
Example with environment variables:
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"mcpServers": {
|
|
88
|
+
"mclocks-datetime-util": {
|
|
89
|
+
"command": "npx",
|
|
90
|
+
"args": ["-y", "mclocks-datetime-util"],
|
|
91
|
+
"env": {
|
|
92
|
+
"MCLOCKS_LOCALE": "ja",
|
|
93
|
+
"MCLOCKS_CONVTZ": "Asia/Tokyo"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
You can also specify a custom config path via the `--config` CLI flag:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"mcpServers": {
|
|
105
|
+
"mclocks-datetime-util": {
|
|
106
|
+
"command": "npx",
|
|
107
|
+
"args": ["-y", "mclocks-datetime-util", "--config", "/path/to/config.json"]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Example usage
|
|
114
|
+
|
|
115
|
+
Once configured, you can ask your AI assistant:
|
|
116
|
+
|
|
117
|
+
- "What time is it now?"
|
|
118
|
+
- "What time is it in Jakarta?"
|
|
119
|
+
- "Convert 1705312200 epoch to datetime"
|
|
120
|
+
- "Convert 2024-01-15T10:30:00Z to Asia/Tokyo"
|
|
121
|
+
- "Next Friday is what date?"
|
|
122
|
+
- "What day of the week is 2026-12-25?"
|
|
123
|
+
- "How many days until Christmas?"
|
|
124
|
+
- "How many days between 2026-01-01 and 2026-12-31?"
|
|
125
|
+
- "What date is 90 days from 2026-04-01?"
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
[The Artistic License 2.0](https://github.com/bayashi/mclocks/blob/main/LICENSE)
|
|
130
|
+
|
|
131
|
+
## Author
|
|
132
|
+
|
|
133
|
+
Dai Okabayashi: https://github.com/bayashi
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -125,6 +125,8 @@ function convertToTimezone(cdt, src, tz, usetz) {
|
|
|
125
125
|
try {
|
|
126
126
|
let result;
|
|
127
127
|
if (usetz) {
|
|
128
|
+
// Use strict timezone conversion for historically accurate UTC offsets.
|
|
129
|
+
// For example, before 1888/1/1 00:00:00 in JST, its utcOffset is 09:18.
|
|
128
130
|
result = cdt(src).tz(tz).text();
|
|
129
131
|
} else {
|
|
130
132
|
const offset = cdt().tz(tz).utcOffset();
|
|
@@ -265,6 +267,23 @@ server.tool(
|
|
|
265
267
|
}
|
|
266
268
|
);
|
|
267
269
|
|
|
270
|
+
server.tool(
|
|
271
|
+
"local-time",
|
|
272
|
+
"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.",
|
|
273
|
+
{},
|
|
274
|
+
async () => {
|
|
275
|
+
const tz = configConvTZ || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
276
|
+
const source = configConvTZ ? "config (convtz)" : "system";
|
|
277
|
+
const now = new Date();
|
|
278
|
+
const cdt = cdate().cdateFn();
|
|
279
|
+
const offset = cdt().tz(tz).utcOffset();
|
|
280
|
+
const result = cdt(now).utcOffset(offset).text();
|
|
281
|
+
return {
|
|
282
|
+
content: [{ type: "text", text: `${result} in ${tz} (source: ${source})` }],
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
|
|
268
287
|
server.tool(
|
|
269
288
|
"next-weekday",
|
|
270
289
|
"Find the date of the next occurrence of a given weekday from today.",
|