A simple package to convert between the Gregorian calendar and the Taiwanese calendar.
Project description
twdate
A simple Python package to convert between the Gregorian calendar and the Taiwanese (Minguo) calendar.
Installation
pip install twdate
Usage
Create a Minguo date
from twcal import TWDate
d = TWDate(115, 3, 20) # 民國115年3月20日
Convert between Gregorian and Minguo
import datetime
from twcal import to_minguo, to_gregorian
# Gregorian -> Minguo
tw = to_minguo(datetime.date(2026, 3, 20))
# TWDate(year=115, month=3, day=20)
# Minguo -> Gregorian
gd = to_gregorian(tw)
# datetime.date(2026, 3, 20)
Get today's date in Minguo format
from twcal import today
d = today()
print(d) # 民國115年3月20日
Format as string
d = TWDate(115, 3, 20)
d.to_string() # '民國115年3月20日'
d.to_short_string() # '1150320'
str(d) # '民國115年3月20日'
Parse from short string
d = TWDate.from_short_string("1150320")
# TWDate(year=115, month=3, day=20)
Pre-Minguo dates
import datetime
from twcal import to_minguo
d = to_minguo(datetime.date(1911, 1, 1))
# TWDate(year=-1, month=1, day=1)
print(d) # 民國前1年1月1日
Comparison
from twcal import TWDate
TWDate(115, 1, 1) > TWDate(114, 12, 31) # True
TWDate(114, 1, 1) < TWDate(115, 1, 1) # True
Validation
from twcal import TWDate
TWDate(0, 1, 1) # ValueError: 民國0年不存在
TWDate(115, 2, 30) # ValueError: day is out of range for month
License
This project is licensed under the MIT License. You are free to use, modify, and distribute this software for any purpose, including commercial use.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twdate-1.0.1.tar.gz.
File metadata
- Download URL: twdate-1.0.1.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e501f99777b29475787ec76de0404eec5b44346687b370aaae13fd99523e79c1
|
|
| MD5 |
2f28e92e940fdc8ba94ef61b7696c37e
|
|
| BLAKE2b-256 |
90e358e9b8eb56a6da00094f41d23b22920195eeee77915f7cb4262072f18ff4
|
Provenance
The following attestation bundles were made for twdate-1.0.1.tar.gz:
Publisher:
publish.yml on yueswater/twcal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twdate-1.0.1.tar.gz -
Subject digest:
e501f99777b29475787ec76de0404eec5b44346687b370aaae13fd99523e79c1 - Sigstore transparency entry: 1141451753
- Sigstore integration time:
-
Permalink:
yueswater/twcal@6d0afae084c4daae0d8392b05570fb3737e2880e -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/yueswater
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6d0afae084c4daae0d8392b05570fb3737e2880e -
Trigger Event:
push
-
Statement type:
File details
Details for the file twdate-1.0.1-py3-none-any.whl.
File metadata
- Download URL: twdate-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
159de62ab5905fdb4b3d8d9ed0e1d93844b07d06e5db3963968ecb80b6788e36
|
|
| MD5 |
b71b625a908db165edd021721a4c3fea
|
|
| BLAKE2b-256 |
928dffe29513644a5f7099a411d0345d968465d90dfda6aced008d5944a359f6
|
Provenance
The following attestation bundles were made for twdate-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on yueswater/twcal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twdate-1.0.1-py3-none-any.whl -
Subject digest:
159de62ab5905fdb4b3d8d9ed0e1d93844b07d06e5db3963968ecb80b6788e36 - Sigstore transparency entry: 1141451788
- Sigstore integration time:
-
Permalink:
yueswater/twcal@6d0afae084c4daae0d8392b05570fb3737e2880e -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/yueswater
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6d0afae084c4daae0d8392b05570fb3737e2880e -
Trigger Event:
push
-
Statement type: