6.11. Time

Time parsers are based upon Text parser and therefore inherits all parameters from it and it’s usage. One differences is that normalize parameter is set to False while in Text parser is set to True by default.

To read docs regarding other parameters than the one described here, please go to Text documentation.

6.11.1. DateTime

class easydata.parsers.time.DateTime(*args, language: Optional[str] = None, locales: Optional[List[str]] = None, region: Optional[str] = None, date_formats: Optional[List[str]] = None, date_order: Optional[str] = None, timezone: Optional[str] = None, to_timezone: Optional[str] = None, return_as_timezone_aware: Optional[str] = None, prefer_day_of_month: Optional[str] = None, prefer_dates_from: Optional[str] = None, relative_base: Optional[datetime.datetime] = None, strict_parsing: Optional[bool] = None, require_parts: Optional[List[str]] = None, skip_tokens: Optional[List[str]] = None, date_normalize: Optional[bool] = None, return_time_as_period: Optional[bool] = None, parsers: Optional[List[str]] = None, fuzzy: Optional[bool] = None, prefer_locale_date_order: Optional[bool] = None, default_languages: Optional[List[str]] = None, language_detection_confidence_threshold: Optional[float] = None, **kwargs)[source]

Bases: easydata.parsers.time.BaseDateTime

DateTime parser will try to convert date time from a string to our custom date time format.

Getting Started

Lets import first easydata module.

>>> import easydata as ed

DateTime supports any query object for fetching data.

>>> test_dict = {'datetime': 'Fri, 10 Dec 2018 10:55:50'}
>>> ed.DateTime(ed.jp('datetime')).parse(test_dict)
'12/10/2018 10:55:50'

Any invalid string without datetime will cause DateTime parser to return None.

>>> test_dict = {'datetime': 'n/a'}
>>> ed.DateTime(ed.jp('datetime')).parse(test_dict)
None

Parameters

datetime_format

We can change our date time output in any valid str format that we want through a datetime_format parameter.

>>> test_date_text = 'Fri, 10 Dec 2018 10:55:50'
>>> ed.DateTime(datetime_format='%d.%m.%Y %H:%M:%S').parse(test_date_text)
'10.12.2018 10:55:50'

Note

Default value of datetime_format parameter can be defined through a config variable ED_DATETIME_FORMAT in a config file or a model.

min_year

If we set value in a min_year parameter and year of our date time in a string is bellow our min year limit, then the output will be None.

Lets try first with a valid year.

>>> test_date_text = 'Fri, 10 Dec 2018 10:55:50'
>>> ed.DateTime(min_year='2015').parse(test_date_text)
'12/10/2018 10:55:50'

Now with a year that it’s bellow our min_year limit.

>>> test_date_text = 'Fri, 10 Dec 2010 10:55:50'
>>> ed.DateTime(min_year='2015').parse(test_date_text)
None
max_year

If we set value in a max_year parameter and year of our date time in a string is over our max year limit, then the output will be None.

Lets try first with a valid year.

>>> test_date_text = 'Fri, 10 Dec 2018 10:55:50'
>>> ed.DateTime(max_year='2020').parse(test_date_text)
'12/10/2018 10:55:50'

Now with a year that it’s over our max_year limit.

>>> test_date_text = 'Fri, 10 Dec 2022 10:55:50'
>>> ed.DateTime(max_year='2020').parse(test_date_text)
None
today
language
locales
region
date_formats
date_order
timezone
to_timezone
return_as_timezone_aware
prefer_day_of_month
prefer_dates_from
relative_base
strict_parsing
require_parts
skip_tokens
date_normalize
return_time_as_period
parsers
fuzzy
prefer_locale_date_order
default_languages
language_detection_confidence_threshold

6.11.2. DateTimeSearch

class easydata.parsers.time.DateTimeSearch(*args, language: Optional[str] = None, locales: Optional[List[str]] = None, region: Optional[str] = None, date_formats: Optional[List[str]] = None, date_order: Optional[str] = None, timezone: Optional[str] = None, to_timezone: Optional[str] = None, return_as_timezone_aware: Optional[str] = None, prefer_day_of_month: Optional[str] = None, prefer_dates_from: Optional[str] = None, relative_base: Optional[datetime.datetime] = None, strict_parsing: Optional[bool] = None, require_parts: Optional[List[str]] = None, skip_tokens: Optional[List[str]] = None, date_normalize: Optional[bool] = None, return_time_as_period: Optional[bool] = None, parsers: Optional[List[str]] = None, fuzzy: Optional[bool] = None, prefer_locale_date_order: Optional[bool] = None, default_languages: Optional[List[str]] = None, language_detection_confidence_threshold: Optional[float] = None, **kwargs)[source]

Bases: easydata.parsers.time.DateTime

DateTimeSearch works exactly the same as DateTime parser with a difference that can extract date time from sentences that have other content besides date time.

Lets try first to extract date from a sentence with a DateTime parser.

As we can see … ordinary

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.DateTime().parse(test_text)
None

As we can see … ordinary DateTime parser cannot handle text if there is some other text besides date time and in situations like this DateTimeSearch parser will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.DateTimeSearch().parse(test_text)
'12/10/2018 10:55:50'

6.11.3. SPDateTime

class easydata.parsers.time.SPDateTime(*args, sp_datetime_format: Optional[str] = None, **kwargs)[source]

Bases: easydata.parsers.time.BaseDateTime

examples coming soon …

Parameters

sp_datetime_format

6.11.4. Date

class easydata.parsers.time.Date(*args, date_format: Optional[str] = None, **kwargs)[source]

Bases: easydata.parsers.time.DateTime

Date parser works exactly the same as DateTime parser but it’s output is only date and it’s has it’s own date_format parameter to format date output.

Getting Started

Lets import first easydata module.

>>> import easydata as ed

Date supports any query object for fetching data.

>>> test_dict = {'datetime': 'Fri, 10 Dec 2018 10:55:50'}
>>> ed.Date(ed.jp('datetime')).parse(test_dict)
'12/10/2018'

Any invalid string without a date will cause Date parser to return None.

>>> test_dict = {'date': 'n/a'}
>>> ed.DateTime(ed.jp('date')).parse(test_dict)
None

Parameters

date_format

We can change our date time output in any valid str format that we want through a date_format parameter.

>>> test_date_text = 'Fri, 10 Dec 2018 10:55:50'
>>> ed.DateTime(date_format='%d.%m.%Y').parse(test_date_text)
'10.12.2018'

Note

Default value of date_format parameter can be defined through a config variable ED_DATE_FORMAT in a config file or a model.

6.11.5. DateSearch

class easydata.parsers.time.DateSearch(*args, date_format: Optional[str] = None, **kwargs)[source]

Bases: easydata.parsers.time.Date

DateSearch works exactly the same as Date parser with a difference that can extract date from sentences that have other content besides date.

Lets try first to extract date from a sentence with a Date parser.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.Date().transform(test_text)
None

As we can see … ordinary

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.Date().transform(test_text)
None

As we can see … ordinary

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.Date().parse(test_text)
None

As we can see … ordinary Date parser cannot handle text if there is some other text besides date and in situations like this DateSearch parser will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.DateSearch().transform(test_text)
'12/10/2018'

will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.DateSearch().transform(test_text)
'12/10/2018'

will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.DateSearch().parse(test_text)
'12/10/2018'

6.11.6. SPDate

class easydata.parsers.time.SPDate(*args, date_format: Optional[str] = None, sp_date_format: Optional[str] = None, **kwargs)[source]

Bases: easydata.parsers.time.SPDateTime

examples coming soon …

Parameters

sp_date_format

6.11.7. Time

class easydata.parsers.time.Time(*args, time_format: Optional[str] = None, **kwargs)[source]

Bases: easydata.parsers.time.DateTime

Time parser works exactly the same as DateTime parser but it’s output is only time and it’s has it’s own time_format parameter to format time output.

Getting Started

Lets import first easydata module.

>>> import easydata as ed

Time supports any query object for fetching data.

>>> test_dict = {'datetime': 'Fri, 10 Dec 2018 10:55:50'}
>>> ed.Time(ed.jp('datetime')).parse(test_dict)
'10:55:50'

Any invalid string without a date will cause Time parser to return None.

>>> test_dict = {'time': 'n/a'}
>>> ed.Time(ed.jp('time')).parse(test_dict)
None

Parameters

time_format

We can change our date time output in any valid str format that we want through a time_format parameter.

>>> test_date_text = 'Fri, 10 Dec 2018 10:55:50'
>>> ed.Time(time_format='%H-%M-%S').parse(test_date_text)
'10-55-50'

Note

Default value of time_format parameter can be defined through a config variable ED_TIME_FORMAT in a config file or a model.

6.11.8. TimeSearch

class easydata.parsers.time.TimeSearch(*args, time_format: Optional[str] = None, **kwargs)[source]

Bases: easydata.parsers.time.Time

TimeSearch works exactly the same as Time parser with a difference that can extract time from sentences that have other content besides time.

Lets try first to extract date from a sentence with a Time parser.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.Time().transform(test_text)
None

As we can see … ordinary

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.Time().transform(test_text)
None

As we can see … ordinary

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.Time().parse(test_text)
None

As we can see … ordinary Time parser cannot handle text if there is some other text besides date and in situations like this TimeSearch parser will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.TimeSearch().transform(test_text)
'10:55:50'

will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.TimeSearch().transform(test_text)
'10:55:50'

will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.TimeSearch().parse(test_text)
'10:55:50'

6.11.9. Year

class easydata.parsers.time.Year(*args, language: Optional[str] = None, locales: Optional[List[str]] = None, region: Optional[str] = None, date_formats: Optional[List[str]] = None, date_order: Optional[str] = None, timezone: Optional[str] = None, to_timezone: Optional[str] = None, return_as_timezone_aware: Optional[str] = None, prefer_day_of_month: Optional[str] = None, prefer_dates_from: Optional[str] = None, relative_base: Optional[datetime.datetime] = None, strict_parsing: Optional[bool] = None, require_parts: Optional[List[str]] = None, skip_tokens: Optional[List[str]] = None, date_normalize: Optional[bool] = None, return_time_as_period: Optional[bool] = None, parsers: Optional[List[str]] = None, fuzzy: Optional[bool] = None, prefer_locale_date_order: Optional[bool] = None, default_languages: Optional[List[str]] = None, language_detection_confidence_threshold: Optional[float] = None, **kwargs)[source]

Bases: easydata.parsers.time.DateTime

Year parser works exactly the same as DateTime parser but it’s output is only year.

Getting Started

Lets import first easydata module.

>>> import easydata as ed

Year supports any query object for fetching data.

>>> test_dict = {'datetime': 'Fri, 10 Dec 2018 10:55:50'}
>>> ed.Year(ed.jp('datetime')).parse(test_dict)
'2018'

Any invalid string without a date will cause Year parser to return None.

>>> test_dict = {'date': 'n/a'}
>>> ed.Year(ed.jp('date')).parse(test_dict)
None

6.11.10. YearSearch

class easydata.parsers.time.YearSearch(*args, language: Optional[str] = None, locales: Optional[List[str]] = None, region: Optional[str] = None, date_formats: Optional[List[str]] = None, date_order: Optional[str] = None, timezone: Optional[str] = None, to_timezone: Optional[str] = None, return_as_timezone_aware: Optional[str] = None, prefer_day_of_month: Optional[str] = None, prefer_dates_from: Optional[str] = None, relative_base: Optional[datetime.datetime] = None, strict_parsing: Optional[bool] = None, require_parts: Optional[List[str]] = None, skip_tokens: Optional[List[str]] = None, date_normalize: Optional[bool] = None, return_time_as_period: Optional[bool] = None, parsers: Optional[List[str]] = None, fuzzy: Optional[bool] = None, prefer_locale_date_order: Optional[bool] = None, default_languages: Optional[List[str]] = None, language_detection_confidence_threshold: Optional[float] = None, **kwargs)[source]

Bases: easydata.parsers.time.Year

YearSearch works exactly the same as Year parser with a difference that can extract time from sentences that have other content besides date.

Lets try first to extract date from a sentence with a Year parser.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.Year().transform(test_text)
None

As we can see … ordinary

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.Year().transform(test_text)
None

As we can see … ordinary

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.Year().parse(test_text)
None

As we can see … ordinary Year parser cannot handle text if there is some other text besides date and in situations like this YearSearch parser will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.YearSearch().transform(test_text)
'2018'

will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.YearSearch().transform(test_text)
'2018'

will work.

>>> test_text = 'It has happened on 10 Dec 2018 at 10:55:50'
>>> ed.YearSearch().parse(test_text)
'2018'