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日

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.1.tar.gz (3.2 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.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

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

Hashes for twdate-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e501f99777b29475787ec76de0404eec5b44346687b370aaae13fd99523e79c1
MD5 2f28e92e940fdc8ba94ef61b7696c37e
BLAKE2b-256 90e358e9b8eb56a6da00094f41d23b22920195eeee77915f7cb4262072f18ff4

See more details on using hashes here.

Provenance

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

Hashes for twdate-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 159de62ab5905fdb4b3d8d9ed0e1d93844b07d06e5db3963968ecb80b6788e36
MD5 b71b625a908db165edd021721a4c3fea
BLAKE2b-256 928dffe29513644a5f7099a411d0345d968465d90dfda6aced008d5944a359f6

See more details on using hashes here.

Provenance

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