Skip to main content

Data type that handles year and month values.

Project description

ym

Data type that handles year and month values.

Usage

Initialize

from year, month

ym(2020, 4)  #=> ym(2020, 4)

from current month

ym.current()  #=> ym(2020, 7)

from string

ym.parse("2020-04")  #=> ym(2020, 4)

from date or datetime object

from datetime import date

ym.parse(date.today())  #=> ym(2020, 7)

Get year, month

current = ym.current()  #=> ym(2020, 7)
current.y  #=> 2020
current.m  #=> 7

Add, Sub

ym(2020, 4) + 10  #=> ym(2021, 2)
ym(2020, 4) - 10  #=> ym(2019, 6)
ym(2020, 7) - ym(2020, 4)  #=> 3

Compare

ym(2020, 7) < ym(2020, 4)  #=> False
ym(2020, 7) > ym(2020, 4)  #=> True
ym(2020, 7) == ym(2020, 4)  #=> False

Range

ym(2020, 4).to(2020, 7)  #=> [ym(2020, 4), ym(2020, 5), ym(2020, 6)]
current = ym.current()  #=> ym(2020, 7)
current.to(current + 6)  #=> [ym(2020, 7), ym(2020, 8), ym(2020, 9), ym(2020, 10), ym(2020, 11), ym(2020, 12)]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ym, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size ym-1.0.1.tar.gz (1.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page