Skip to main content

CQCalendar is a lightweight, tick-based time and calendar system for Python games and simulations.

Project description

CQCalendar v1.1.1

CQCalendar is a lightweight, tick-based time and calendar system for Python games and simulations.

It is designed for RPGs, sandbox sims, and systemic games, where time drives world behavior rather than just displaying a UI clock.


Features

  • Tick-based and absolute time progression
  • Gregorian calendar with leap year support
  • Weekday tracking
  • Synodic lunar cycle (moon phases & illumination)
  • Event callbacks for hour/day/month/year changes
  • Designed for decoupled, systemic game logic
  • No external dependencies

Installation

You can install CQCalendar using pip.

pip install cqcalendar

How to Create a Calendar for Your Game

import cqcalendar

calendar = cqcalendar.CQCalendar(
  hour=9,
  minute=0,
  is_pm=False,
  minutes_per_tick=1,
  day=1,
  month=1,
  year=1,
  weekday=0,
  moon_age_days=0.0,
  moon_phase=None,
  debug_callbacks=False,
)

Time

How to Display Current Time

print(calendar.time_string())

How to Change Time

calendar.set_time(hour=12, minute=0, is_pm=True)

How to Increment Time

calendar.update(ticks=10)

Date

How to Display Current Date

print(calendar.date_string())

How to Change Date

calendar.set_date(day=31, month=12, year=1)

Absolute Time Advancement

You can advance time directly without ticks.

calendar.add_minutes(30)
calendar.add_hours(6)
calendar.add_days(1)
calendar.add_months(1)
calendar.add_years(1)

Or you can do it in a single method.

calendar.add(days=3, hours=4)

Weekdays

Weekdays are zero-indexed (0 = Monday, 6 = Sunday).

How to Display Weekday

print(calendar.weekday_name())

How to Change Weekday

calendar.set_weekday(weekday=1)

Lunar Cycle

CQCalendar includes a synodic lunar cycle (approximately 29.53 days)

How to Display Moon Phase

print(calendar.moon_phase_name())

How to Set Moon Phase

calendar.set_moon_phase("Waning Crescent")

The above is an alternative to using moon_age_days:

# Precise numeric control still supported
calendar = CQCalendar(moon_age_days=14.77) # Full Moon

If both moon_phase and moon_age_days are provided, moon_phase takes priority.

How to Get Moon Illumination

print(calendar.moon_illumination())

Useful for:

  • werewolf systems
  • rituals
  • night visibility
  • tides or magic strength

Callbacks (Events)

CQCalendar allows systems to react to time changes using callbacks.

Callbacks are triggered when time crosses a boundary (hour/day/month/year), not continuously.

Hourly Event

def restock_shops(calendar):
  if calendar.hour == 6 and not calendar.is_pm:
    print("Shops restocked!")

calendar.on_hour(restock_shops)

Daily Event

def payday(calendar):
  if calendar.day == 1:
    print("Rent is due!")

calendar.on_day(payday)

Available callbacks:

  • on_hour
  • on_day
  • on_month
  • on_year

Misc.

How to Display Current Date and Time

print(calendar.datetime_string())

Related Libraries

  • TerraForge: A versatile Python toolset for procedural map generation.
  • MoonTex: A noise-based texture generator that creates realistic grayscale moon phase images.

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

cqcalendar-1.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

cqcalendar-1.1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file cqcalendar-1.1.1.tar.gz.

File metadata

  • Download URL: cqcalendar-1.1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for cqcalendar-1.1.1.tar.gz
Algorithm Hash digest
SHA256 dab4dcdfc4f0259b8e567c892139c4beeaa0ba9571cea9332ca6d24f1c260589
MD5 f6a3a675e5bac48ca1e504879a24072d
BLAKE2b-256 6d61d15c6f7006219183d79790053ebc02cf6178df1a4780340422e49b6007f5

See more details on using hashes here.

File details

Details for the file cqcalendar-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: cqcalendar-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for cqcalendar-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db81a445b98554388f1b0cc1ecd8f6cad5e8b8764e99cf7523faa915c78259f5
MD5 2f32f3bd7e5d97771a123cd18fa106e3
BLAKE2b-256 b19e23efa278bc72dfd17738a85372bd6f63b7516f2ab7b7bfd618f7e18061fe

See more details on using hashes here.

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