Live data from Hacker News

Pendulum – Python datetimes made easy

github.com

71–76 of 76 posts

Re: Pendulum – Python datetimes made easy

#71
post #60

Earlier quoted context omitted.

>>> from datetime import datetime, timedelta >>> datetime.now() - (datetime.now() + timedelta(days=1)) datetime.timedelta(-2, 86399, 999969)

I’m not entirely sure what you were trying to demonstrate, but clearly the result of datetime.now() changes between the two invocations (it has microsecond precision). Try: >>> from datetime import datetime, timedelta >>> now = datetime.now() >>> now - (now + timedelta(days=1)) datetime.timedelta(-1)

datetime.timedelta internally uses a triple of (days,seconds,microseconds) to represent it's data and exposes that to users of the class.

That a timedelta can be represented in multiple ways is alone quite surprising but some of the representations that happen can be very confusing. I think the example I gave which represents "-1 day and a few microseconds" as "-2 days + 86399 milliseconds + 999969 microseconds" is very surprising and it commonly happens in practice.

For comparison, here's what postgres does:

    postgres=> select now() - (now() + '12 milliseconds'::interval + '1 day'::interval);
           ?column?        
    -----------------------
     -1 days -00:00:00.012
    (1 row)

Re: Pendulum – Python datetimes made easy

#72
post #69

Earlier quoted context omitted.

What libraries? I'm honestly interested to know which ones you refer to.

https://dateutil.readthedocs.io http://crsmithdev.com/arrow/ http://pythonhosted.org/pytz/ http://delorean.readthedocs.io http://github.hubspot.com/sanetime/ https://github.com/zachwill/moment https://docs.djangoproject.com/en/1.10/topics/i18n/timezones... The most similar to this are Arrow and Delorean, maybe Django timezone if you use Django.

So, basically, you haven't read any of my comments. Arrow is really flawed see https://pendulum.eustace.io/faq/#why-not-arrow and Delorean is not as complete feature-wise as Pendulum. Both of these libraries do not handle properly shifting time around DST transition times which is a big flaw in itself beacause it's not accurate.

Re: Pendulum – Python datetimes made easy

#73
post #60

Earlier quoted context omitted.

I’m not entirely sure what you were trying to demonstrate, but clearly the result of datetime.now() changes between the two invocations (it has microsecond precision). Try: >>> from datetime import datetime, timedelta >>> now = datetime.now() >>> now - (now + timedelta(days=1)) datetime.timedelta(-1)

datetime.timedelta internally uses a triple of (days,seconds,microseconds) to represent it's data and exposes that to users of the class. That a timedelta can be represented in multiple ways is alone quite surprising but some of the representations that happen can be very confusing. I think the example I gave which represents "-1 day and a few microseconds" as "-2 days + 86399 milliseconds + 999969 microseconds" is v…

That's a problem Pendulum is trying to solve

    d1 = datetime(2012, 1, 1, 1, 2, 3, tzinfo=pytz.UTC)
    d2 = datetime(2011, 12, 31, 22, 2, 3, tzinfo=pytz.UTC)
    delta = d2 - d1
    delta.days
    -1
    delta.seconds
    75600
    
    d1 = Pendulum(2012, 1, 1, 1, 2, 3)
    d2 = Pendulum(2011, 12, 31, 22, 2, 3)
    delta = d2 - d1
    delta.days
    0
    delta.hours
    -3

Re: Pendulum – Python datetimes made easy

#74

Earlier quoted context omitted.

I also really like the Timestamp class, are the obvious reasons not to use it?

Having pandas as a dependency?

That doesn't seem like a terrible dependency, is that the only reason?

Re: Pendulum – Python datetimes made easy

#75
post #59
post #10

Earlier quoted context omitted.

So far I haven't seen either of these libraries do substantially better than datetime+dateutil+pytz at anything they claim to be good at.

I'm happy to not have to import 3 libraries anymore (2 that aren't part of standard library) to see if one date is greater than another or to add few days to a date.

They both import all three under the hood.

Re: Pendulum – Python datetimes made easy

#76
post #29

I don't understand why this library exists. I am (literally) manipulating datetimes for a living in a Django app this whole year and we don't even have Arrow installed. Pytz and maybe dateutil is all you need. Also I really hate when someone fragment the energy and their time making a new, inferior library instead of fixing and patching the existings for basic things like this. This way we will have a bunch of incomp…

Also manipulating datetimes for a living (telemetry + billing). The reason I stick with Arrow despite its slowing maintainership? Its ability to round up or down time along a granularity: http://crsmithdev.com/arrow/#arrow.arrow.Arrow.floor
Post reply on HN