{"record":{"id":"e5d46594eba86112","repo":"cube-js/cube","slug":"unknown-timezone-timezone","errorCode":null,"errorMessage":"Unknown timezone: ${timezone}","messagePattern":"Unknown timezone: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-shared/src/time.ts","lineNumber":277,"sourceCode":"export const FROM_PARTITION_RANGE = '__FROM_PARTITION_RANGE';\n\nexport const TO_PARTITION_RANGE = '__TO_PARTITION_RANGE';\n\nexport const BUILD_RANGE_START_LOCAL = '__BUILD_RANGE_START_LOCAL';\n\nexport const BUILD_RANGE_END_LOCAL = '__BUILD_RANGE_END_LOCAL';\n\n/**\n * Takes timestamp, treat it as time in provided timezone and returns the corresponding timestamp in UTC\n */\nexport const localTimestampToUtc = (timezone: string, timestampFormat: string, timestamp?: string): string | null => {\n  if (!timestamp) {\n    return null;\n  }\n  if (timestamp.length === 23 || timestamp.length === 26) {\n    const zone = moment.tz.zone(timezone);\n    if (!zone) {\n      throw new Error(`Unknown timezone: ${timezone}`);\n    }\n\n    const parsedTime = Date.parse(`${timestamp}Z`);\n    const offset = zone.utcOffset(parsedTime);\n    const inDbTimeZoneDate = new Date(parsedTime + offset * 60 * 1000);\n\n    if (timestampFormat === 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' || timestampFormat === 'YYYY-MM-DDTHH:mm:ss.SSSZ') {\n      return inDbTimeZoneDate.toJSON();\n    } else if (timestampFormat === 'YYYY-MM-DD[T]HH:mm:ss.SSSSSS[Z]' || timestampFormat === 'YYYY-MM-DDTHH:mm:ss.SSSSSSZ') {\n      const value = inDbTimeZoneDate.toJSON();\n      if (value.endsWith('999Z')) {\n        // emulate microseconds\n        return value.replace('Z', '999Z');\n      }\n\n      // emulate microseconds\n      return value.replace('Z', '000Z');\n    } else if (timestampFormat === 'YYYY-MM-DDTHH:mm:ss.SSS') {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-shared/src/time.ts#L259-L295","documentation":"localTimestampToUtc in packages/cubejs-backend-shared/src/time.ts converts a 23- or 26-character local timestamp to UTC using the IANA timezone's offset via moment.tz.zone(timezone). If the timezone name is not a valid IANA zone (moment returns no zone object), it throws 'Unknown timezone'. This prevents silently applying UTC offsets of 0 for unrecognized zones.","triggerScenarios":"localTimestampToUtc('2024-01-01T00:00:00.000', 'America/NewYork') or any call where timezone is misspelled, a fixed-offset string like 'UTC+2', an empty string, or a Windows zone name like 'Eastern Standard Time' — with a timestamp of length 23 or 26.","commonSituations":"Timezone read from user config/browser with wrong casing or typos; Windows (CLDR) timezone names instead of IANA names; environment defaults like 'local' or 'system' passed through.","solutions":["Pass a valid IANA timezone name, e.g. 'America/New_York', 'Europe/Berlin', 'UTC'.","Validate with moment.tz.zone(tz) (or Intl.supportedValuesOf('timeZone')) before calling.","Convert Windows/CLDR zone names to IANA (e.g. via a CLDR-to-IANA mapping library) before use.","Check casing/whitespace: normalize (trim, exact case) the configured timezone."],"exampleFix":"// before\nlocalTimestampToUtc(ts, 'Eastern Standard Time'); // throws\n\n// after\nlocalTimestampToUtc(ts, 'America/New_York');","handlingStrategy":"validation","validationCode":"import moment from 'moment-timezone';\nfunction assertTimezone(tz: string) {\n  if (!moment.tz.zone(tz)) {\n    throw new Error(`'${tz}' is not a valid IANA timezone; see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones`);\n  }\n}","typeGuard":"function isIanaTimezone(tz: unknown): tz is string {\n  return typeof tz === 'string' && tz.length > 0 && moment.tz.zone(tz) !== null;\n}","tryCatchPattern":"try {\n  return localTimestampToUtc(ts, tz);\n} catch (e) {\n  if (/Unknown timezone/.test(String(e))) {\n    console.warn(`Unknown timezone '${tz}', falling back to UTC`);\n    return localTimestampToUtc(ts, 'UTC');\n  }\n  throw e;\n}","preventionTips":["Store only IANA names ('America/New_York'), never fixed offsets or Windows names","Validate timezone at config-load and at API boundaries","Map CLDR/Windows zone names to IANA before use","Add Intl.supportedValuesOf('timeZone') check in browsers"],"tags":["timezone","dates","validation","iana"],"backgroundTag":"unknown-timezone","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}