A modular time and calendar engine with customizable ticks, sun/moon altitude tables, and dynamic parameter propagation.
Project description
A battle-tested, headless time & calendar engine for games, simulations, automation—and anything else that needs a clock.
Problem
Projects that simulate a world—whether it’s a game, a physics engine, a climate model, or an automation pipeline—inevitably need:
- A reliable clock with a reliable calendar to back it
- Accurate celestial data (sunrise/sunset, moon phases, altitudes)
- Event hooks so subsystems can react to time-changes
- Robust rollover logic and edge-case handling
Rolling your own solution is error-prone, time-consuming, and quickly becomes a maintenance nightmare as your project grows.
Solution
format_time turns “build-an-engine-from-scratch” into “install-and-go.” It provides:
-
🎲 Modular Core
- Pure-Python
Timeclass:.advance(ticks),.current_datetime() - Fully configurable calendar units (ticks/hr, hrs/day, days/month, months/yr)
- Pure-Python
-
🌙 Sun & Moon Tables
- Precomputed NumPy arrays for fast altitude lookups
- Automatic rebuilds when you tweak calendar parameters
-
♻️ Dynamic Parameters
ParametersManagerbacked by SQLite- Change any parameter at runtime—everything updates instantly
-
🔔 Event Notifications
- UDP-broadcast on every tick advance
- Easy listeners for UIs, game loops, analytics pipelines
-
✅ Production-Quality
- 112 tests (unit, edge-case, integration, module)
- Black / isort / flake8 pre-commit hooks
- Python 3.12+ support, MIT license
Installation
# Core engine only
pip install format_time_engine
# GIS / astronomy extras (sun & moon tables)
pip install format_time_engine[geo]
# Qt & matplotlib for custom UIs
pip install format_time_engine[ui]
# Everything
pip install format_time_engine[geo,ui]
Quickstart
from time_engine.unified_time_module import UnifiedTimeModule
utm = UnifiedTimeModule(data_dir="calendar_data")
# Advance by 3,600 ticks
utm.time.advance(3600)
# Read current datetime
dt = utm.time.current_datetime()
print(
f"{dt['year']}-{dt['month']:02}-{dt['day']:02} "
f"{dt['hour']:02}:{dt['tick']}/{utm.time.ticks_per_hour} ticks"
)
# Query sun altitude
sun_alt = utm.sun_api().get_altitude()
print(f"Sun altitude: {sun_alt:.1f}°")
Configuration
All core parameters live in a SQLite database (parameters.db). Change them on the fly:
from parameters.manager import ParametersManager
pm = ParametersManager()
pm.set("time", "hours_per_day", "30")
# calendars and notifications rebuild automatically
Override the DB path:
export PARAM_DB_PATH=/path/to/my_params.db
Contributing
- Fork & clone
git clone git@github.com:ProphetGang/format_time.git cd format_time
- Install dev tools
pip install -e .[dev] pre-commit install pre-commit run --all-files pytest
License
This project is MIT-licensed. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file format_time_engine-1.0.1.tar.gz.
File metadata
- Download URL: format_time_engine-1.0.1.tar.gz
- Upload date:
- Size: 4.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3c568ff20fd55a543b563847d246a41fadf6ba752d017515029e995d951c357
|
|
| MD5 |
67609c269a55dd0a7daa6c2a06ab668b
|
|
| BLAKE2b-256 |
b66ee120a52ef665aa8962ce47f897f52e9b7be2e97a87eef5054f94ff31f7df
|
File details
Details for the file format_time_engine-1.0.1-py3-none-any.whl.
File metadata
- Download URL: format_time_engine-1.0.1-py3-none-any.whl
- Upload date:
- Size: 50.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be3b2f721828802e1fba1801b1f3982efca247ff5a7b5aeb6e6e9f80ede43a2f
|
|
| MD5 |
69fe36164f5448ab02f4efbb87c090fa
|
|
| BLAKE2b-256 |
d64e8e6c482a81aceac7270856c0d310aa3ff2b0914dbab8869af7698c38f0ca
|