scrapinghub / scrapinghub/dateparser

More Support for Parsing dates with Timezones

Open
#298 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Enhancement
Dominant language
Python
Stars
2.9k
Forks
520
Avg merge
22h 56m
Merged PRs (30d)
6

Description

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'>)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the dateparser.parse examples in the issue and inspect how timezone settings and timezone text are currently handled. Compare abbreviated, offset, regional, long-form, and non-English examples, then verify that the requested examples produce timezone-aware results without breaking existing parsing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
localization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.