Skip to main content

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

Project description

CQCalendar

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

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,
  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 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.

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.0.0.tar.gz (5.7 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.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cqcalendar-1.0.0.tar.gz
Algorithm Hash digest
SHA256 23de71a644fe2a8c6c446c32d58c9c163ce68fe0e1794b5d35c96308bdadbb3a
MD5 2cc4db373597843c25229d4765bc2fa1
BLAKE2b-256 5de4ef704fd917ec900cadc883a911b8afabb6865a5a8c4010f86803d5ebb5e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cqcalendar-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8bcf4873993872bf6388574d19c476dafecf723fd5bba96be33b25ddc997e3c
MD5 c4655d5a5fef15f607f4573a7f5a2cb6
BLAKE2b-256 5efd42ab3db20fe328e46367192ba6d6904509ae158600bfafbcd3a62ec6f56f

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