1

I've just read

BBC: Samoa and Tokelau skip a day for dateline change, 30.12.2011

I wanted to see this with pytz, but everything I tried only showed an offset of -11, but not of +13 or +14:

>>> import pytz
>>> tz = pytz.timezone('Pacific/Samoa')
>>> tz_us = pytz.timezone('US/Samoa')
>>> import datetime
>>> datetime.datetime(2011, 12, 30, 9, 00, tzinfo=datetime.timezone.utc).astimezone(tz).isoformat()
'2011-12-29T22:00:00-11:00'
>>> datetime.datetime(2011, 12, 30, 10,00, tzinfo=datetime.timezone.utc).astimezone(tz).isoformat()
'2011-12-29T23:00:00-11:00'
>>> datetime.datetime(2011, 12, 30, 11, 00, tzinfo=datetime.timezone.utc).astimezone(tz).isoformat()
'2011-12-30T00:00:00-11:00'
>>> datetime.datetime(2011, 12, 31, 15, 00, tzinfo=datetime.timezone.utc).astimezone(tz).isoformat()
'2011-12-31T04:00:00-11:00'
>>> datetime.datetime(2015, 12, 31, 15, 00, tzinfo=datetime.timezone.utc).astimezone(tz).isoformat()
'2015-12-31T04:00:00-11:00'
>>> datetime.datetime(2011, 12, 31, 15, 00, tzinfo=datetime.timezone.utc).astimezone(tz_us).isoformat()
'2011-12-31T04:00:00-11:00'
>>> datetime.datetime(2015, 12, 31, 15, 00, tzinfo=datetime.timezone.utc).astimezone(tz_us).isoformat()
'2015-12-31T04:00:00-11:00'

Why can't I see the offset +13 / +14?

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • If I take your question literally, the answer is one of geopolitics and regional economics. If that is not your question, please edit your question to reflect your intended question. Also consider tagging the relevant language/frameworks you are utilizing. – Andrew Fan Aug 29 '18 at 19:07
  • The "geopolitics and regional economics" answer would be wrong, if I understand wikipedia + the article right. They do have +13 or +14 (both due to DST), but not -11. – Martin Thoma Aug 29 '18 at 19:11

1 Answers1

1

Both Pacific/Samoa and US/Samoa are aliases of Pacific/Pago_Pago, representing American Samoa, which is UTC-11 and did not skip that day.

  • For American Samoa, use Pacific/Pago_Pago

  • For the Independent State of Samoa, use Pacific/Apia

  • For Tokelau, use Pacific/Fakaofo

Personally, I prefer to only use canonical zone names. See the list on Wikipedia for reference.

See the timezone change with pytz

UTC time with offset:

>>> import pytz
>>> tz = pytz.timezone('Pacific/Apia')
>>> import datetime
>>> datetime.datetime(2011, 12, 30, 9, 59, tzinfo=datetime.timezone.utc).astimezone(tz).isoformat()
'2011-12-29T23:59:00-10:00'
>>> datetime.datetime(2011, 12, 30, 10, 00, tzinfo=datetime.timezone.utc).astimezone(tz).isoformat()
'2011-12-31T00:00:00+14:00'

Local time:

>>> '{:%Y-%m-%d %H:%M}'.format(datetime.datetime(2011, 12, 30, 9, 59, tzinfo=datetime.timezone.utc).astimezone(tz))
'2011-12-29 23:59'
>>> '{:%Y-%m-%d %H:%M}'.format(datetime.datetime(2011, 12, 30, 10, 00, tzinfo=datetime.timezone.utc).astimezone(tz))
'2011-12-31 00:00'
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Nice! May I add the code that shows what I wanted to see? – Martin Thoma Aug 30 '18 at 05:05
  • How did you look up the time zones? I used [this answer](https://stackoverflow.com/q/13866926/562769) and searched for "Samoa", but this way I would never have found `Pacific/Apia` – Martin Thoma Aug 30 '18 at 05:07
  • https://gist.github.com/MartinThoma/2c59338684dfdd63e75dae69d76b9130 is what I would add. – Martin Thoma Aug 30 '18 at 05:12
  • 1
    Sure, always feel free to edit if it's constructive. As far as how to find them, it helps to know the geography in the region. Also, the list on Wikipedia has the two-character country code, so that's a great cross-reference. Additionally, http://timeanddate.com has an expanded city lookup, and from there you can usually figure out the right IANA zone id. If you want to do it programatically from lat/lon coordinates, see https://stackoverflow.com/questions/16086962/how-to-get-a-time-zone-from-a-location-using-latitude-and-longitude-coordinates – Matt Johnson-Pint Aug 30 '18 at 17:57