Resolving Ambiguous DST Times for Twilio Message Scheduling and TaskRouter Worker Availability
0 reputation · 13 Jun 2023, 03:25 UTC
0 reputation · 13 Jun 2023, 03:25 UTC
Developers must convert regional local times to UTC for Twilio message scheduling and TaskRouter worker availability.
Twilio's send_at parameter requires an ISO 8601 UTC timestamp and TaskRouter worker timezone strings must be valid IANA zones; during DST fallback the same local time occurs twice, requiring a decision on which offset to apply.
Which UTC offset (standard or daylight) should be used when converting ambiguous local times to UTC for Twilio send_at and TaskRouter worker scheduling?
35775 reputation · 13 Jun 2023, 07:08 UTC
The standard (later) offset—i.e., the IANA fold flag set to 1 (standard time)—should be used when converting ambiguous local times to UTC for Twilio send_at and TaskRouter worker scheduling.
During DST fallback the same wall‑clock time occurs twice: first with a daylight offset (fold 0) and then with a standard offset (fold 1). The IANA tz database marks the later occurrence as fold 1. Industry best practice (RFC 5545, ICU, java.time, Python PEP 495, Noda Time) is to treat the later (standard) occurrence as the default for future‑scheduled events, because the daylight offset will have already ended.
ZonedDateTime (or equivalent) using the zone identifier and explicitly selecting the standard offset (fold = 1). In Java: ZonedDateTime.of(local, zone, ZoneOffset.ofHours(-5)) for America/New_York after the fallback.send_at parameter.America/New_York) and let TaskRouter handle UTC conversion; do not supply ambiguous local times directly.2026-11-01T06:30Z for the example 2026‑11‑01 02:30 America/New_York.send_at returns a Message SID; a 400 Bad Request with “Invalid send_at timestamp” means the UTC time was malformed or in the past.Available flag matches the expected UTC window.zdump -v America/New_York | grep 2026 in the container to verify the transition instant and the standard offset used.Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 13 Jun 2023, 05:33 UTC
Twilio's send_at and TaskRouter accept only UTC timestamps and IANA zone strings respectively — neither exposes a DST-disambiguation parameter. During fallback transitions (e.g., 2026-11-01 01:30 America/New_York), most standard libraries (Java java.time, Python zoneinfo, Node Intl.DateTimeFormat) default to the earlier offset (EDT, UTC-4) unless you explicitly request the later one (EST, UTC-5).
To guarantee the standard-time interpretation, convert in application code with an explicit policy before calling Twilio:
dt.replace(fold=1) then .astimezone(timezone.utc)ZonedDateTime.ofInstant(local, ZoneOffsetTransitionRule.STANDARD)time.LoadLocation then time.Date(..., 0, loc) with fold=1 via time.Time.InTest against known fallback dates (e.g., first Sunday in November for US zones) and verify the IANA tzdata version in your runtime (zdump -v or equivalent) to avoid silent drift from rule changes.