Skip to main content

A simple package to convert between the Gregorian calendar and the Taiwanese calendar.

Project description

twcal

中文版

A simple Python package to convert between the Gregorian calendar and the Taiwanese (Minguo) calendar.

Installation

pip install twcal

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


Download files

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

Source Distribution

twdate-1.0.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twdate-1.0.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file twdate-1.0.0.tar.gz.

File metadata

  • Download URL: twdate-1.0.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for twdate-1.0.0.tar.gz
Algorithm Hash digest
SHA256 50f094c876e23249c694c48974ed6afc0417845f1770a584ef7c6ad3ed17e852
MD5 e71f432b3637aedb586d84862a6b3f3a
BLAKE2b-256 0bcb58820671094b8f10eda3ddb878327c20ce96189803bac4ddeff3b9b46816

See more details on using hashes here.

Provenance

The following attestation bundles were made for twdate-1.0.0.tar.gz:

Publisher: publish.yml on yueswater/twcal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file twdate-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: twdate-1.0.0-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

Hashes for twdate-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1394614b7a938e0b3e937ab2d85cd4e691c65880eacc6413b0d3c4e178f21460
MD5 d7a5a3405d408e5a2ed2811a9923ad17
BLAKE2b-256 975aaab417d5effa83b44f4dc91e71988e2bfb8b5ff8403ba46bda897521db15

See more details on using hashes here.

Provenance

The following attestation bundles were made for twdate-1.0.0-py3-none-any.whl:

Publisher: publish.yml on yueswater/twcal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page