<story><title>Pendulum – Python datetimes made easy</title><url>https://github.com/sdispater/pendulum</url></story><parent_chain><item><author>sdispater</author><text>Pendulum is a new library for Python to ease datetimes, timedeltas and timezones manipulation.&lt;p&gt;It is heavily inspired by [Carbon](&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;carbon.nesbot.com&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;carbon.nesbot.com&lt;/a&gt;) for PHP.&lt;p&gt;Basically, the Pendulum class is a replacement for the native datetime one with some useful and intuitive methods, the Interval class is intended to be a better time delta class and, finally, the Period class is a datetime-aware timedelta.&lt;p&gt;Timezones are also easier to deal with: Pendulum will automatically normalize your datetime to handle DST transitions for you.&lt;p&gt;&lt;pre&gt;&lt;code&gt;    import pendulum
    
    pendulum.create(2013, 3, 31, 2, 30, 0, 0, &amp;#x27;Europe&amp;#x2F;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
    &amp;#x27;2013-03-31T03:30:00+02:00’
    
    dt = pendulum.create(2013, 3, 31, 1, 59, 59, 999999, &amp;#x27;Europe&amp;#x2F;Paris’)
    &amp;#x27;2013-03-31T01:59:59.999999+01:00’
    dt = dt.add(microseconds=1)
    &amp;#x27;2013-03-31T03:00:00+02:00’
    dt.subtract(microseconds=1)
    &amp;#x27;2013-03-31T01:59:59.999998+01:00’
&lt;/code&gt;&lt;/pre&gt;
To those wondering: yes I know [Arrow](&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;crsmithdev.com&amp;#x2F;arrow&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;crsmithdev.com&amp;#x2F;arrow&amp;#x2F;&lt;/a&gt;) exists but its flaws and strange API (you can throw almost anything at get() and it will do its best to determine what you wanted, for instance) motivated me to start this project. You can check why I think Arrow is flawed here: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;pendulum.eustace.io&amp;#x2F;faq&amp;#x2F;#why-not-arrow&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;pendulum.eustace.io&amp;#x2F;faq&amp;#x2F;#why-not-arrow&lt;/a&gt;&lt;p&gt;Link to the official documentation: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;pendulum.eustace.io&amp;#x2F;docs&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;pendulum.eustace.io&amp;#x2F;docs&amp;#x2F;&lt;/a&gt;&lt;p&gt;Link to the github project: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;sdispater&amp;#x2F;pendulum&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;sdispater&amp;#x2F;pendulum&lt;/a&gt;</text></item></parent_chain><comment><author>jsmeaton</author><text>Cool library, I&amp;#x27;ll definitely be looking into this more closely in the future. The automatic handling of ambiguous time during timezone transitions is curious. As an example, Django punts on automatic handling and requires a user to choose between pre and post transition (I wrote the is_dst handling): &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;django&amp;#x2F;django&amp;#x2F;blob&amp;#x2F;19e20a2a3f763388bba9263d56db34012e90cf5b&amp;#x2F;django&amp;#x2F;utils&amp;#x2F;timezone.py#L368&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;django&amp;#x2F;django&amp;#x2F;blob&amp;#x2F;19e20a2a3f763388bba926...&lt;/a&gt;&lt;p&gt;What if you were to begin with a time at 3:30 and then subtract an hour. Would your library properly return 1:30? What if a user had a naive time at 3:30, subtracted an hour, and then converted to an aware time using your library? For what it&amp;#x27;s worth, I think moving to 3:30 is the correct behaviour in the vast amount of cases. Requiring a user to provide a direction to move and throwing an exception if they don&amp;#x27;t is dangerous. How often are users going to see this exception, if at all? Just wondering how much you&amp;#x27;ve considered cases, if they exist, that would be better off moving to 1:30.&lt;p&gt;I&amp;#x27;ll add one more thing. As soon as I started browsing the page I thought &amp;quot;why would I use this over arrow?&amp;quot;. Great to see you addressed that by default. I didn&amp;#x27;t know about some of arrows shortcomings&amp;#x2F;bugs, so they were really useful.&lt;p&gt;Handling dates, times, and timezones in particular is a tricky problem, as evident by the large number of libraries in each language trying to get it right. If you haven&amp;#x27;t already, I&amp;#x27;d really recommend reading the blog posts of Jon Skeet regarding Noda Time &lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;blog.nodatime.org&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;blog.nodatime.org&amp;#x2F;&lt;/a&gt; and &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;codeblog.jonskeet.uk&amp;#x2F;category&amp;#x2F;nodatime&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;codeblog.jonskeet.uk&amp;#x2F;category&amp;#x2F;nodatime&amp;#x2F;&lt;/a&gt; even if it turns up some corner cases you haven&amp;#x27;t considered, or validates ones you have.&lt;p&gt;Thanks!</text></comment>
<story><title>Pendulum – Python datetimes made easy</title><url>https://github.com/sdispater/pendulum</url></story><parent_chain><item><author>sdispater</author><text>Pendulum is a new library for Python to ease datetimes, timedeltas and timezones manipulation.&lt;p&gt;It is heavily inspired by [Carbon](&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;carbon.nesbot.com&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;carbon.nesbot.com&lt;/a&gt;) for PHP.&lt;p&gt;Basically, the Pendulum class is a replacement for the native datetime one with some useful and intuitive methods, the Interval class is intended to be a better time delta class and, finally, the Period class is a datetime-aware timedelta.&lt;p&gt;Timezones are also easier to deal with: Pendulum will automatically normalize your datetime to handle DST transitions for you.&lt;p&gt;&lt;pre&gt;&lt;code&gt;    import pendulum
    
    pendulum.create(2013, 3, 31, 2, 30, 0, 0, &amp;#x27;Europe&amp;#x2F;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
    &amp;#x27;2013-03-31T03:30:00+02:00’
    
    dt = pendulum.create(2013, 3, 31, 1, 59, 59, 999999, &amp;#x27;Europe&amp;#x2F;Paris’)
    &amp;#x27;2013-03-31T01:59:59.999999+01:00’
    dt = dt.add(microseconds=1)
    &amp;#x27;2013-03-31T03:00:00+02:00’
    dt.subtract(microseconds=1)
    &amp;#x27;2013-03-31T01:59:59.999998+01:00’
&lt;/code&gt;&lt;/pre&gt;
To those wondering: yes I know [Arrow](&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;crsmithdev.com&amp;#x2F;arrow&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;crsmithdev.com&amp;#x2F;arrow&amp;#x2F;&lt;/a&gt;) exists but its flaws and strange API (you can throw almost anything at get() and it will do its best to determine what you wanted, for instance) motivated me to start this project. You can check why I think Arrow is flawed here: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;pendulum.eustace.io&amp;#x2F;faq&amp;#x2F;#why-not-arrow&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;pendulum.eustace.io&amp;#x2F;faq&amp;#x2F;#why-not-arrow&lt;/a&gt;&lt;p&gt;Link to the official documentation: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;pendulum.eustace.io&amp;#x2F;docs&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;pendulum.eustace.io&amp;#x2F;docs&amp;#x2F;&lt;/a&gt;&lt;p&gt;Link to the github project: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;sdispater&amp;#x2F;pendulum&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;sdispater&amp;#x2F;pendulum&lt;/a&gt;</text></item></parent_chain><comment><author>dvl</author><text>I already faced some of mentioned problems using Arrow, I&amp;#x27;ll give pendulum a try tomorrow.</text></comment>