Created by: sdispater
Why this framework/library/software/resource is awesome?
Pendulum aims at making Python datetimes easy. It fixes the flaw of the existing libraries (especially Arrow) while providing a more explicit API. Here are some examples:
import pendulum
now = pendulum.now('Europe/Paris')
# Changing timezone
now.in_timezone('America/Toronto')
# Default support for common datetime formats
now.to_iso8601_string()
# Shifting time
now.add(days=2)
It improves the native timedelta
type:
it = pendulum.interval(days=15)
# More properties
it.weeks
it.hours
# Handy methods
it.in_hours()
360
it.in_words(locale='en_us')
'2 weeks 1 day'
It brings its own Period
class, which is a datetime-ware timedelta
:
dt1 = pendulum.now()
dt2 = dt1.add(days=3)
# A period is the difference between 2 instances
period = dt2 - dt1
period.in_weekdays()
period.in_weekend_days()
# A period is iterable
for dt in period:
print(dt)
And finally, it improves timezones manipulation by handling normalization properly and shifting time around DST transition time:
import pendulum
pendulum.create(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris')
#2:30 for the 31th of March 2013 does not exist
# so pendulum will return the actual time which is 3:30+02:00
'2013-03-31T03:30:00+02:00'
in_utc = pendulum.create(2013, 3, 31, 0, 59, 59, 999999)
tz = pendulum.timezone('Europe/Paris')
in_paris = tz.convert(in_utc)
'2013-03-31T01:59:59.999999+01:00'
# Shifting time
in_paris = in_paris.add(microseconds=1)
'2013-03-31T03:00:00+02:00'
in_paris.subtract(microseconds=1)
'2013-03-31T01:59:59.999999+01:00'
For the rest you can check out the official documentation: https://pendulum.eustace.io/docs/
Anyone who agrees with this pull request could vote for it by adding a