• FAQ
    • Journal
    • Personal ☤ Values
    • Online References
    • Recommendations
    • Tattoos
    • Travel Log
    • ☤ B l a c k b o x ☤
    • BTC & ETH
    • Games
    • ☤ Software for Humans ☤
    • « Podcast »
    • Essays on Development
    • Python-Guide.org (H2G2P)
    • Requests: HTTP for Humans
    • The "Say Thanks" Project.
    • Records: SQL for Humans
    • Maya: Datetimes for Humans
    • Certifi: TLS Trust for Humans
    • Autoenv (Magic CD-ing)
    • em: cli emoji keyboard
    • HTTPbin Testing Service
    • ☤ Conference Talks ☤
    • github.com/kennethreitz
    • ☤ About KR Photography ☤
    • Essays on Photography
    • Flickr (Journal)
    • 500px (portfolio)
    • YouPic (Models)
    • Instagram
  • Sound
  • Video
    • ☤ Conference Talks ☤
    • Scheduled Events
    • Travel Log
    • ☤ All Essays ☤
    • Development
    • Journeys
    • Music
    • Photography
    • Objects
    • ☤ Archives ☤
  • Journal
  • VLOG
Menu

Kenneth Reitz

  • K ☤ R
    • FAQ
    • Journal
    • Personal ☤ Values
    • Online References
    • Recommendations
    • Tattoos
    • Travel Log
    • ☤ B l a c k b o x ☤
    • BTC & ETH
  • Code
    • Games
    • ☤ Software for Humans ☤
    • « Podcast »
    • Essays on Development
    • Python-Guide.org (H2G2P)
    • Requests: HTTP for Humans
    • The "Say Thanks" Project.
    • Records: SQL for Humans
    • Maya: Datetimes for Humans
    • Certifi: TLS Trust for Humans
    • Autoenv (Magic CD-ing)
    • em: cli emoji keyboard
    • HTTPbin Testing Service
    • ☤ Conference Talks ☤
    • github.com/kennethreitz
  • Light
    • ☤ About KR Photography ☤
    • Essays on Photography
    • Flickr (Journal)
    • 500px (portfolio)
    • YouPic (Models)
    • Instagram
  • Sound
  • Video
  • Talks
    • ☤ Conference Talks ☤
    • Scheduled Events
    • Travel Log
  • Essays
    • ☤ All Essays ☤
    • Development
    • Journeys
    • Music
    • Photography
    • Objects
    • ☤ Archives ☤
  • Journal
  • VLOG

Essays by KR — development, music, photography, journeys, objects, & archive.

Introducing Maya: Datetimes for Humans™

December 18, 2016

Datetimes are a headache to deal with in Python, especially when dealing with timezones, especially when dealing with different machines with different locales. 

Maya exists to do all the hard work for you, so you can focus on what you're trying to do — import or export simple datetime data in known human and machine-readable formats. 

Example Usage of Maya (v0.1.0)

>>> now = maya.now()
<MayaDT epoch=1481850660.9>

>>> tomorrow = maya.when('tomorrow')
<MayaDT epoch=1481919067.23>

>>> tomorrow.slang_date()
'tomorrow'

>>> tomorrow.slang_time()
'23 hours from now'

>>> tomorrow.iso8601()
'2016-12-16T15:11:30.263350Z'

>>> tomorrrow.rfc2822()
'Fri, 16 Dec 2016 20:11:30 -0000'

>>> tomorrow.datetime()
datetime.datetime(2016, 12, 16, 15, 11, 30, 263350, tzinfo=<UTC>)

# Automatically parse datetime strings and generate naive datetimes.
>>> scraped = '2016-12-16 18:23:45.423992+00:00'
>>> maya.parse(scraped).datetime(to_timezone='US/Eastern', naive=True)
datetime.datetime(2016, 12, 16, 13, 23, 45, 423992)

>>> rand_day = maya.when('2011-02-07', timezone='US/Eastern')
<MayaDT epoch=1297036800.0>

# Note how this is the 6th, not the 7th.
>>> rand_day.day
6

# Always.
>>> rand_day.timezone
'UTC'

Why is this useful?

  • All timezone algebra will behave identically on all machines, regardless of system locale.
  • Complete symmetric import and export of both ISO 8601 and RFC 2822 datetime stamps.
  • Fantastic parsing of both dates written for/by humans and machines (maya.when() vs. maya.parse()).
  • Support for human slang, both import and export (e.g. 'an hour ago').
  • Datetimes can very easily be generated, with our without timezone information attached (naive).
  • This library is based around epoch time, but dates before Jan 1 1970 are indeed supported, via negative integers.
  • Maya never panics, and always carrys a towel.

What about Delorean, Arrow, & Pendulum?

Arrow, for example, is a fantastic library, but isn't what I wanted in a datetime library. In many ways, it's better than Maya for certian things. In some ways, in my opinion, it's not.

I simply desire a sane API for datetimes that made sense to me for all the things I'd ever want to do—especially when dealing with timezone algebra. Arrow doesn't do all of the things I need (but it does a lot more!). Maya does do exactly what I need.

I think these projects compliment each-other, personally. Maya is great for parsing websites, for example. Arrow supports floors and ceilings and spans of dates, which Maya does not at all.

Installing Maya

$ pip install maya

✨🍰✨

External Links

  • Maya on GitHub
  • Maya in The Cheeseshop
  • Say Thanks™
In Development
← The Reality of Developer BurnoutTest-Driving a $200 Coding Font: Operator Mono →

Recent Posts

Essays
Apple Pencil Note-Taking: Why You Should Use Apple Notes, actually.
about 5 days ago
First Soundtrack Scoring!
about 2 months ago
Logitech CRAFT Keyboard Video Review
about 2 months ago
Leica M10 Video Review
about 2 months ago

Recent Music


Messages to Humans

Receive updates on upcoming projects, new releases, and interesting things from Kenneth Reitz.

Subscribe to Newsletter

Join the Messages for Humans mailing list to receive updates on new releases and upcoming projects. 

 

✨ 🍰 ✨

 

Have a question or comment? Post it in the FAQ Forum.

 

(essays archive, blog rss feed)

External Content. Personal Values. Tattoos. Travel History. Upcoming Events. Archive.