Code Monkey home page Code Monkey logo

Comments (8)

sigmavirus24 avatar sigmavirus24 commented on May 31, 2024

Please fix the documentation to not hate on Python datetime objects because of a misunderstanding.

My recommendation would be to update the documentation to provide an example of how to add timezone information, either with pytz, the datetime library itself, or (preferably) both. It's not terribly hard and a little Google search should help you find how to do that appropriately.

from analytics-python.

masklinn avatar masklinn commented on May 31, 2024

They don't "lose timezone information", whatever that means. You're not giving timezone information to the now() function in the first place. Try this: datetime.datetime.now(tz=pytz.utc).

Of note, in Python 3 the maintainers added a UTC instance to the standard library (so you don't need pytz just to get UTC zoned datetimes), and support for fixed-offset timezones. This support has also been added to strptime, so if you parse a datetime string with a fixed-time offset and the %z operator you'll get a zoned datetime (in Python 2, %z in strptime is an error):

>>> datetime.strptime("2015-03-15T07:54:13-1045", "%Y-%m-%dT%H:%M:%S%z")
datetime.datetime(2015, 3, 15, 7, 54, 13, tzinfo=datetime.timezone(datetime.timedelta(-1, 47700)))

You still have to use pytz for "named" timezones.

from analytics-python.

sametmax avatar sametmax commented on May 31, 2024

Or really, just use arrow, which abstract all that stuff, and let you go from and to datetime when you need it.

from analytics-python.

masklinn avatar masklinn commented on May 31, 2024

Or really, just use arrow, which abstract all that stuff, and let you go from and to datetime when you need it.

Except that's not really what arrow does, it mostly asserts that there's no such thing as a date, a time, or a naive datetime (then adds a bunch of utility methods and handrolls localisation and formatting because apparently the CLDR still isn't a thing)

from analytics-python.

sperand-io avatar sperand-io commented on May 31, 2024

Thanks @dwieeb. Completely agree; point well made and very appreciated. @jgershen to accompany your release this sprint, would you mind updating the docs to reflect the proper approach and remove disparaging/embarrassing language? (And close this once it's done?) Thanks!

from analytics-python.

jgershen avatar jgershen commented on May 31, 2024

Yep, the stuff we had there sure is incorrect & embarrassing; I'll fix the docs. Thanks @dwieeb for bringing it to our attention!

from analytics-python.

jgershen avatar jgershen commented on May 31, 2024

Updated to remove the wrong language and add a brief description of how naive / aware objects work.

from analytics-python.

imhoffd avatar imhoffd commented on May 31, 2024

👍

Thanks, this is great!

from analytics-python.

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.