Skip to content

TZInfo::AmbiguousTime: 1895-12-31 23:59:59 UTC is an ambiguous local time. (Asia/Taipei) #1

Description

@yorkxin

I have a Rails app that defaults time zone to "Asia/Taipei" (UTC+8). Sometimes an exception like this would be raised:

TZInfo::AmbiguousTime: 1895-12-31 23:59:59 UTC is an ambiguous local time.

With tzinfo 0.3.37 (which Rails depends on), this exception can be reproduced in irb:

> time = Time.new(1895,12,31,23,59,59)
 => 1895-12-31 23:59:59 +0800

> TZInfo::Timezone.get("Asia/Taipei").local_to_utc(time)
 => TZInfo::AmbiguousTime: Time: 1895-12-31 23:59:59 UTC is an ambiguous local time.

> TZInfo::Timezone.get("Asia/Shanghai").local_to_utc(time)
 => 1895-12-31 15:54:02 UTC

Both Asia/Taipei and Asia/Shanghai are in UTC+8 today, and have no official time zone in 1895.

This issue does not happen if I load tzinfo 1.0.1, which uses TZ Database directly from OS. If I install both tzinfo 1.0.1 and tzinfo-data gems, this issue would happen again (in this case tzinfo takes tzinfo-data instead of OS-provided TZ DB). However Rails binds version of tzinfo to >= 0.3.37, so I cannot work around this by simply upgrading tzinfo to 1.0.x.

I confirmed that such exception would happen if the local time to convert is between 1895-12-31 23:54:00 and 1895-12-31 23:59:59, and noticed that, in the original TZ Database, the following definition exists:

# Zone  NAME        GMTOFF  RULES   FORMAT  [UNTIL]
Zone    Asia/Taipei 8:06:00 -       LMT     1896 # or Taibei or T'ai-pei
                    8:00    Taiwan  C%sT

I want to make sure:

  • Which is the expected behavior? Ambiguous time? Or correctly converted like Asia/Shanghai?
  • Is there a rare case that is not handled in the converter of tzinfo-data?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions