@coo-quack/calc-mcp 1.7.1 → 1.7.2

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.
Files changed (2) hide show
  1. package/dist/index.js +51 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -31145,6 +31145,10 @@ function countShiftJisBytes(text) {
31145
31145
  bytes += 1;
31146
31146
  } else if (code >= 65377 && code <= 65439) {
31147
31147
  bytes += 1;
31148
+ } else if (code === 165 || code === 8254) {
31149
+ bytes += 1;
31150
+ } else if (code > 65535) {
31151
+ bytes += 1;
31148
31152
  } else {
31149
31153
  bytes += 2;
31150
31154
  }
@@ -31224,7 +31228,7 @@ function parseField(field, min, max) {
31224
31228
  }
31225
31229
  return { values };
31226
31230
  }
31227
- function getNextOccurrences(fields, count) {
31231
+ function getNextOccurrences(fields, count, timezone = "UTC") {
31228
31232
  const minute = parseField(fields[0], 0, 59);
31229
31233
  const hour = parseField(fields[1], 0, 23);
31230
31234
  const dom = parseField(fields[2], 1, 31);
@@ -31232,17 +31236,57 @@ function getNextOccurrences(fields, count) {
31232
31236
  const dow = parseField(fields[4], 0, 6);
31233
31237
  const results = [];
31234
31238
  const now = new Date;
31235
- const current = new Date(now);
31239
+ let formatter;
31240
+ try {
31241
+ formatter = new Intl.DateTimeFormat("en-US", {
31242
+ timeZone: timezone,
31243
+ year: "numeric",
31244
+ month: "2-digit",
31245
+ day: "2-digit",
31246
+ hour: "2-digit",
31247
+ minute: "2-digit",
31248
+ hour12: false
31249
+ });
31250
+ } catch (_error) {
31251
+ throw new Error(`Invalid timezone: "${timezone}". Must be a valid IANA timezone identifier.`);
31252
+ }
31253
+ const partMap = new Map;
31254
+ function parseInTimezone(date6) {
31255
+ const parts = formatter.formatToParts(date6);
31256
+ partMap.clear();
31257
+ for (const part of parts) {
31258
+ partMap.set(part.type, part.value);
31259
+ }
31260
+ const get = (type) => partMap.get(type) ?? "0";
31261
+ const year = Number.parseInt(get("year"), 10);
31262
+ const month2 = Number.parseInt(get("month"), 10);
31263
+ const day = Number.parseInt(get("day"), 10);
31264
+ let parsedHour = Number.parseInt(get("hour"), 10);
31265
+ const parsedMinute = Number.parseInt(get("minute"), 10);
31266
+ if (parsedHour === 24) {
31267
+ parsedHour = 0;
31268
+ }
31269
+ const parsedDow = new Date(Date.UTC(year, month2 - 1, day)).getUTCDay();
31270
+ return {
31271
+ year,
31272
+ month: month2,
31273
+ day,
31274
+ hour: parsedHour,
31275
+ minute: parsedMinute,
31276
+ dow: parsedDow
31277
+ };
31278
+ }
31279
+ const current = new Date(now.getTime() + 60000);
31236
31280
  current.setSeconds(0, 0);
31237
- current.setMinutes(current.getMinutes() + 1);
31238
31281
  const maxIterations = 525600;
31239
31282
  let iterations = 0;
31240
31283
  while (results.length < count && iterations < maxIterations) {
31241
31284
  iterations++;
31242
- if (month.values.has(current.getMonth() + 1) && dom.values.has(current.getDate()) && dow.values.has(current.getDay()) && hour.values.has(current.getHours()) && minute.values.has(current.getMinutes())) {
31285
+ const parsed = parseInTimezone(current);
31286
+ if (month.values.has(parsed.month) && dom.values.has(parsed.day) && dow.values.has(parsed.dow) && hour.values.has(parsed.hour) && minute.values.has(parsed.minute)) {
31243
31287
  results.push(new Date(current));
31244
31288
  }
31245
- current.setMinutes(current.getMinutes() + 1);
31289
+ current.setTime(current.getTime() + 60000);
31246
31290
  }
31247
31291
  return results;
31248
31292
  }
@@ -31259,7 +31303,8 @@ function execute7(input) {
31259
31303
  throw new Error(`Expected 5 fields (minute hour dom month dow), got ${fields.length}`);
31260
31304
  }
31261
31305
  const count = input.count ?? 5;
31262
- const occurrences = getNextOccurrences(fields, count);
31306
+ const timezone = input.timezone ?? "UTC";
31307
+ const occurrences = getNextOccurrences(fields, count, timezone);
31263
31308
  return JSON.stringify({
31264
31309
  expression: input.expression,
31265
31310
  description: describeCron(fields),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coo-quack/calc-mcp",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "calc-mcp": "dist/index.js"