morpheus-cli 0.7.0 → 0.7.1

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.
@@ -135,6 +135,22 @@ function parsePortugueseTimeExpression(expression, refDate, timezone) {
135
135
  }
136
136
  return null;
137
137
  }
138
+ /**
139
+ * Converts an IANA timezone name (e.g. "America/Sao_Paulo") to a UTC offset in minutes.
140
+ * chrono-node only understands abbreviations (EST, BRT) and numeric offsets,
141
+ * NOT IANA names — passing an unrecognised string makes it silently fall back
142
+ * to the system timezone, which breaks on servers running in UTC.
143
+ */
144
+ function ianaToOffsetMinutes(timezone, refDate) {
145
+ try {
146
+ const utcStr = refDate.toLocaleString('en-US', { timeZone: 'UTC' });
147
+ const tzStr = refDate.toLocaleString('en-US', { timeZone: timezone });
148
+ return Math.round((new Date(tzStr).getTime() - new Date(utcStr).getTime()) / 60_000);
149
+ }
150
+ catch {
151
+ return 0; // fall back to UTC on invalid timezone
152
+ }
153
+ }
138
154
  function formatDatetime(date, timezone) {
139
155
  try {
140
156
  return date.toLocaleString('en-US', {
@@ -180,7 +196,9 @@ export function parseScheduleExpression(expression, type, opts = {}) {
180
196
  }
181
197
  // 4. chrono-node NLP fallback ("tomorrow at 9am", "next friday", etc.)
182
198
  if (!parsed) {
183
- const results = chrono.parse(expression, { instant: refDate, timezone });
199
+ // chrono-node does NOT support IANA timezone names — convert to numeric offset
200
+ const tzOffset = ianaToOffsetMinutes(timezone, refDate);
201
+ const results = chrono.parse(expression, { instant: refDate, timezone: tzOffset });
184
202
  if (results.length > 0 && results[0].date()) {
185
203
  parsed = results[0].date();
186
204
  }