A Chinese lunar date Python library 中国农历日期 Python 库
Installation
$ pip install cnlunardate
Usage
Basic operations:
>>> from cnlunardate import cnlunardate
>>> # Basic constructors
>>> cnlunardate(2017, 6, 1) # 4th attribute defaults to False (month is not leap)
cnlunardate.cnlunardate(2017, 6, 1, False)
>>> cnlunardate(2017, 6, 1, True) # (month is leap)
cnlunardate.cnlunardate(2017, 6, 1, True)
>>> # Conversions from/to solar date
>>> from datetime import date
>>> d = cnlunardate.fromsolardate(date(2017, 6, 24))
>>> d
cnlunardate.cnlunardate(2017, 6, 1, False)
>>> d.tosolardate()
datetime.date(2017, 6, 24)
Other supported operations as datetime.date (including pickling):
>>> d = cnlunardate.fromordinal(736504) # 736504th day after 0001, 1, 1
>>> d
cnlunardate.cnlunardate(2017, 6, 1, False)
>>> d.toordinal()
736504
>>> # A cnlunardate object is immutable; all operations produce a new object
>>> d.replace(year=2018)
cnlunardate.cnlunardate(2018, 6, 1, False)
>>> d.replace(isLeapMonth=True)
cnlunardate.cnlunardate(2017, 6, 1, True)
>>> d
cnlunardate.cnlunardate(2017, 6, 1, False)
>>> d.weekday() # 0 = Monday
5
>>> d.isoweekday() # 1 = Monday
6
>>> t = d.timetuple()
>>> for i in t:
... print(i)
...
2017 # year
6 # month
24 # day
0
0
0
5 # weekday (0 = Monday)
175 # 175th day in the year
-1
>>> ic = d.isocalendar()
>>> for i in ic:
... print(i)
...
2017 # ISO year
25 # ISO week number
6 # ISO day number ( 1 = Monday )
>>> today = cnlunardate.today()
>>> today
cnlunardate.cnlunardate(2019, 11, 22, False)
>>> import time
>>> today == cnlunardate.fromtimestamp(time.time())
True
>>> cnlunardate.min
cnlunardate.cnlunardate(1900, 1, 1, False)
>>> cnlunardate.max
cnlunardate.cnlunardate(2100, 12, 1, False)
Errors:
>>> cnlunardate(2101, 1, 1)
ValueError: year 2101 must be in 1900..2100
>>> cnlunardate(2017, 13, 1)
ValueError: month 13 must be in 1..12
>>> cnlunardate(2017, 1, 30)
ValueError: day 30 must be in 1..29
>>> cnlunardate(2017, 1, 1, True)
ValueError: month 1 is not leap in 2017
>>> from datetime import timedelta
>>> cnlunardate.min - timedelta(days=1)
OverflowError: result out of range
>>> cnlunardate.max + timedelta(days=1)
OverflowError: result out of range
>>> cnlunardate("Hello")
TypeError: an integer is required (got type str)
Testing
$ pytest
License
MIT
Reference
Metadata
Release files for cnlunardate 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cnlunardate-0.0.2.tar.gz | 7.4 kB | Without provenance | Details for cnlunardate-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cnlunardate-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for cnlunardate-0.0.2-py3-none-any.whl |
Total release size: 15.7 kB
Release files / cnlunardate-0.0.2.tar.gz
| Download URL | cnlunardate-0.0.2.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9c9b9c97d0456fb69d1dce7508d42e687194db9f1e15f337d0894efb1d8bd3fc
|
|
BLAKE2b-256 checksum How to use checksums |
d350e988fb3fe403cb6f11a5096a28535c96bb2c82a086f391d2ea098f3e26ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.4
|
Release files / cnlunardate-0.0.2-py3-none-any.whl
| Download URL | cnlunardate-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
264a5acfb7b3ed41f00a1e4768fe69c55dd137e1482f36884fe105653b44cf67
|
|
BLAKE2b-256 checksum How to use checksums |
393bfb8a94c32a3d15011155dbde4ecd7469ca90a5f9a3d6675f31e72e0b8fc6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.4
|
Security for cnlunardate 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.