PyTime

PyTime is an easy-use Python module which aims to operate date/time/datetime by string.

Popularity
2.4
Stable
Activity
0.0
Stable
159
7
24

Description

PyTime is a easy-use Python module which aims to operate date/time/datetime by string.

PyTime allows you using nonregular datetime string to generate and calculate datetime at most situation.

It Also provides you some simple useful methods for getting datetime you want.

Code Quality Rank: L4
Programming language: Python
License: MIT License
Latest version: v0.2.0

PyTime alternatives and similar packages

Based on the "Date and Time" category.
Alternatively, view PyTime alternatives based on common mentions on social networks and blogs.

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.

Do you think we are missing an alternative of PyTime or a related project?

Add another 'Date and Time' Package

README

PyTime

Build Status PyPI version Supported Python versions

PyTime is an easy-use Python module which aims to operate date/time/datetime by string.

PyTime allows you using nonregular datetime string to generate and calculate datetime at most situation.

It Also provides you some simple useful methods for getting datetime you want.

Install

pip install pytime

Sample Usage

Calculate datetime all by string, accept unit for short or overall length, support out of order or in capital unit:

>>>from pytime import pytime
>>>
>>>pytime.before('2015εΉ΄5月17ζ—₯', '2years 3mon 23week 3d 2hr') # 2years 3months 23weeks 3days 2hours before 2015εΉ΄5月17ζ—₯
datetime.datetime(2012, 9, 5, 22, 0)
>>>
>>>pytime.after(pytime.tomorrow('15.5.17'), '23month3dy29minu') # 23months 3days 29minutes after 2015εΉ΄5月17ζ—₯'s next day
datetime.datetime(2017, 4, 21, 0, 29)

Parse nonregular datetime string to datetime:

>>>pytime.parse('April 3rd 2015')
datetime.date(2015, 4, 3)
>>>pytime.parse('Oct, 1st. 2015')
datetime.date(2015, 10, 1)
>>>pytime.parse('NOV21th2015')
datetime.date(2015, 11, 21)
>>>
>>>pytime.parse('2015517')
datetime.date(2015, 5, 17)
>>>
>>>pytime.parse('5/17/15')
datetime.date(2015, 5, 17)
>>>
>>>pytime.parse('92-11-2')
datetime.date(1992, 11, 2)
>>>
>>>pytime.parse(1432310400) # support datetimestamp for all function
datetime.datetime(2015, 5, 23, 0, 0)

Calculate week and month in a easy way. Normally we want to use these binate date in script, from Monday to next Monday which means 00:00:00-23:59:59, and Month from 1st to next 1st in the same way, but if you want clean date interval, you could set pytime.next_week(clean=True) to get the clean date for next week etc.

>>>pytime.this_week()
(datetime.date(2015, 5, 11), datetime.date(2015, 5, 18))
>>>pytime.next_week('2015εΉ΄6月14ζ—₯') # 2015εΉ΄6月14ζ—₯'s next week for script
(datetime.date(2015, 6, 15), datetime.date(2015, 6, 23))
>>>pytime.last_week(pytime.mother(2013), True) # 2013 Mother's Day's last week
(datetime.date(2013, 5, 13), datetime.date(2013, 5, 20))
>>>pytime.next_month('2015εΉ΄10月1ζ—₯')
(datetime.date(2015, 11, 1), datetime.date(2015, 12, 1))

Pytime support calculate timedelta by string even between date and datetime, merely set the date to that day's midnight:

>>>pytime.count('2015εΉ΄5月17ζ—₯ 23:23:23', pytime.tomorrow())
datetime.timedelta(1, 84203)

Get common festivals for designated year:

>>>pytime.father() # Father's Day
datetime.date(2015, 6, 21)
>>>
>>>pytime.mother(2016) # 2016 Mother's Day
datetime.date(2016, 5, 8)
>>>
>>>pytime.easter(1999) # 1999 Easter
datetime.date(1999, 4, 4)
>>>pytime.vatertag(2020) # Fater's Day in Germany
datetime.date(2020, 5, 21)

Get days between two date.

>>>pytime.days_range('2015εΉ΄5月17ζ—₯', '2015εΉ΄5月23ζ—₯')
[datetime.date(2015, 5, 23),
 datetime.date(2015, 5, 22),
 datetime.date(2015, 5, 21),
 datetime.date(2015, 5, 20),
 datetime.date(2015, 5, 19),
 datetime.date(2015, 5, 18),
 datetime.date(2015, 5, 17)]

...

and other useful methods.

Contributors

License

MIT


*Note that all licence references and agreements mentioned in the PyTime README section above are relevant to that project's source code only.

Do not miss the trending, packages, news and articles with our weekly report.

Awesome Python is part of the LibHunt network. Terms. Privacy Policy.

(CC)
BY-SA
We recommend Spin The Wheel Of Names for a cryptographically secure random name picker.

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /