A Chinese lunar date Python library
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cnlunardate-0.0.4.tar.gz
(7.4 kB
view details)
Built Distribution
File details
Details for the file cnlunardate-0.0.4.tar.gz
.
File metadata
- Download URL: cnlunardate-0.0.4.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
1d4f2c1ee7455ffecdf9b7479ecfe13887c4911fdef6f03b332569834b8be9d5
|
|
MD5 |
c0bd76b2aa484c0c587ac2e86ab704dc
|
|
BLAKE2b-256 |
728b5cee63b2f2b33c0efe6724dc2fcedf67b9739d3437f316df2bc0d6be8cd1
|
File details
Details for the file cnlunardate-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: cnlunardate-0.0.4-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
c3b3bacf18eeca959f6a2108ed739ac83e278f173f83ff92b84d3a6c43a7daf0
|
|
MD5 |
1e89eece8f2eaca05a861f0005b10094
|
|
BLAKE2b-256 |
f21cedaf0a46fc6b279462b5d1930d89ab5b924192a89a5d9862034cd39e27d5
|