Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A awesome-python
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 13
    • Issues 13
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 317
    • Merge requests 317
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Vinta Chen
  • awesome-python
  • Merge requests
  • !696

Add Pendulum to Date and Time libraries

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/sdispater/add-pendulum into master Aug 16, 2016
  • Overview 1
  • Commits 2
  • Pipelines 0
  • Changes 1

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 👍 to it, and usually, the maintainer will merge it when votes reach 20.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/sdispater/add-pendulum