Coder Social home page Coder Social logo

Comments (11)

Carreau avatar Carreau commented on August 16, 2024

Hum, the alternative is to use datetime.utcnow() I guess.

But good point.

from jupyter_client.

jcb91 avatar jcb91 commented on August 16, 2024

Actually, datetime.utcnow() still doesn't return a timezone-aware datetime object (I've no idea why, really, UTC seems simple enough that it could be part of standard library, but hey ho). To remove dependency on pytz, something like this SO answer, which defines a tzinfo class for UTC, might be a better solution...

from jupyter_client.

jcb91 avatar jcb91 commented on August 16, 2024

see, for reference, the difference in the two print statements from this snippet:

from datetime import datetime, timedelta, tzinfo

TDZERO = timedelta(0)

class UTC(tzinfo):
    """A UTC tzinfo class"""

    def utcoffset(self, dt):
        return TDZERO

    def tzname(self, dt):
        return 'UTC'

    def dst(self, dt):
        return TDZERO

utc = UTC()

print('utcnow', datetime.utcnow().isoformat())
print('tz=utc', datetime.now(tz=utc).isoformat())

gives

utcnow 2016-03-21T19:03:04.625622
tz=utc 2016-03-21T19:03:04.625970+00:00

from jupyter_client.

Carreau avatar Carreau commented on August 16, 2024

Actually, datetime.utcnow() still doesn't return a timezone-aware datetime object (I've no idea why, really, UTC seems simple enough that it could be part of standard library, but hey ho)

Sorry I was unclear in my statement, we could normalize the spec saying that the date time should be UTC if the current spec is not precise enough.
Of course for backward compatibility we should encourage people to have timezone, but I think in the long term, having UTC everywhere (execpt on user facing UI) make sens.

from jupyter_client.

jcb91 avatar jcb91 commented on August 16, 2024

Right, gotcha. Still, I think it's worth adding the timezone to the string values as well, rather than just altering the spec to allow people to assume they're in UTC - after all Explicit is better than implicit 😉

from jupyter_client.

takluyver avatar takluyver commented on August 16, 2024

We already have three copies of the machinery to produce tz-aware UTC timestamps - there's one in jupyter_client, but it's currently in the tests (test_jsonutil to be precise). I'm pretty sure that UTC timestamps are the way to go, not localised timezone-aware timestamps.

from jupyter_client.

jcb91 avatar jcb91 commented on August 16, 2024

Oh absolutely, utc is the way forward, I just meant the offset (of zero, naturally) should get included in the json-ified text version, as with the utcnow in test_jsonutil.

from jupyter_client.

Carreau avatar Carreau commented on August 16, 2024

Oh absolutely, utc is the way forward, I just meant the offset (of zero, naturally) should get included in the json-ified text version, as with the utcnow in test_jsonutil.

Do I smell a Pull Request coming ?

from jupyter_client.

jcb91 avatar jcb91 commented on August 16, 2024

Haha 😆 I'm happy to submit one, I was a little apprehensive of adding yet another mechanism to produce tz-aware timestamps! If you guys know where you'd like to put it, I'll be happy to fix it up...

from jupyter_client.

minrk avatar minrk commented on August 16, 2024

We can have nice tz-aware utc timestamps with the stdlib in Python 3 with:

datetime.datetime.now(datetime.timezone.utc)

Python 2, of course, needs an backport of the trivial UTC timezone, which we have implemented here (and elsewhere). We can use utc for that, I suppose.

from jupyter_client.

minrk avatar minrk commented on August 16, 2024

master (will be 5.0) uses timezone-aware datetimes.

from jupyter_client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.