Skip to main content

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日

CLI

# Show today's date in Minguo format
twdate now

# Convert Gregorian to Minguo
twdate convert 2026-03-20

# Convert Minguo to Gregorian
twdate convert -g 115-03-20

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.1.0.tar.gz (3.6 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.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for twdate-1.1.0.tar.gz
Algorithm Hash digest
SHA256 991ef61df276f9c94c2a98d0aa8ec8c033598cec2e5e5f448667fa6ed1cfd9a5
MD5 1bdec7c6631e8c464a5bd9c88b9f10d0
BLAKE2b-256 84553c4c8794b790dedccf280a2d5539f1040f9d733ee14a1316db4f225cbe2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for twdate-1.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: twdate-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f3753b09a6d840c9832aa256d587eb68ef0c2102f57f963f2911e4f1eedd14d
MD5 ed52e3015ff0a6c5f7f305e4e00c5e32
BLAKE2b-256 db68b23b0074bf5aa135d707c0bd0ba328320ad6cc4d14ab69631bea302f969a

See more details on using hashes here.

Provenance

The following attestation bundles were made for twdate-1.1.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