Skip to content

More Support for Parsing dates with Timezones #298

Open

Description

@sarthakmadaan

dateparser supports timezones in abbreviated standard formats, UTC or GMT offsets and in regional formats like 'Australia/Sydney'.

   >>> dateparser.parse('15 May 1972 10:15 pm',settings={'TIMEZONE':'IST','RETURN_AS_TIMEZONE_AWARE':True})
   datetime.datetime(1972, 5, 15, 22, 15, tzinfo=<StaticTzInfo 'IST'>)
   >>> dateparser.parse('15 May 1972 10:15 pm',settings={'TIMEZONE':'UTC+5:00','RETURN_AS_TIMEZONE_AWARE':True})
   datetime.datetime(1972, 5, 15, 22, 15, tzinfo=<StaticTzInfo 'UTC\+05:00'>)
   >>> dateparser.parse('15 May 1972 10:15 pm',settings={'TIMEZONE':'Africa/Windhoek','RETURN_AS_TIMEZONE_AWARE':True})
   datetime.datetime(1972, 5, 15, 22, 15, tzinfo=<DstTzInfo 'Africa/Windhoek' SAST+2:00:00 STD>)

It also supports parsing date string with timezone, but timezone needs to be in standard abbreviated format or as UTC or GMT offset.

>>> dateparser.parse('1 nov 1976 12:34 pm EDT',settings={'RETURN_AS_TIMEZONE_AWARE':True})
datetime.datetime(1976, 11, 1, 12, 34, tzinfo=<StaticTzInfo 'EDT'>)
>>> dateparser.parse('1 nov 1976 12:34 pm utc+7',settings={'RETURN_AS_TIMEZONE_AWARE':True})
datetime.datetime(1976, 11, 1, 12, 34, tzinfo=<StaticTzInfo 'UTC\+07:00'>)

I think dateparser should support timezones in long standard format. It does not support regional or long formats for timezones included in date string. Also there is no support for parsing dates with timezones in other languages except English. The following dates should also be parsed in a way as mentioned below.

>>> dateparser.parse('15 May 1972 10:15 pm',settings={'TIMEZONE':'India Standard Time','RETURN_AS_TIMEZONE_AWARE':True})
datetime.datetime(1972, 5, 15, 22, 15, tzinfo=<StaticTzInfo 'IST'>)
>>> dateparser.parse('1 nov 1976 12:34 pm Australia/Sydney')
datetime.datetime(1976, 11, 1, 12, 34, tzinfo=<DstTzInfo 'Australia/Sydney' AEDT+11:00:00 DST>)
>>> dateparser.parse('19 june 1984 10:06 am Pacific Standard Time')
datetime.datetime(1984, 6, 19, 10, 6, tzinfo=<StaticTzInfo 'PST'>)
>>> dateparser.parse('अठारह अगस्त 2000 10:06 पूर्वाह्न जापान मानक समय')   ###(Hindi) 18  August 2000 10:06 am Japan Standard Time
datetime.datetime(2000, 8, 18, 10, 6, tzinfo=<StaticTzInfo 'JST'>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions