Skip to main content

django-chrono is a helper class for date and time operations in Django projects.

Project description

django-chrono

django-chrono is a helper class for date and time operations in Django projects.

Usage Examples

1. String ↔ Datetime

from django_chrono import ChronoUtils

dt = ChronoUtils.str_to_datetime("2025-06-07 16:30:00")
dt_str = ChronoUtils.datetime_to_str(dt, fmt="%d.%m.%Y %H:%M")
# Result: '07.06.2025 16:30'

2. Date ↔ Datetime

import datetime
from django_chrono import ChronoUtils

d = datetime.date(2025, 6, 7)
dt = ChronoUtils.date_to_datetime(d)  # 2025-06-07 00:00:00
d2 = ChronoUtils.datetime_to_date(dt) # 2025-06-07

3. Timestamps

dt = ChronoUtils.timestamp_to_datetime(1759991100)
ts = ChronoUtils.datetime_to_timestamp(dt)

4. Time Zone Conversion

import pytz
from django.utils import timezone

dt = ChronoUtils.str_to_datetime("2025-06-07 12:00:00", tz=pytz.timezone('Europe/Sofia'))
dt_utc = ChronoUtils.to_utc(dt)            # Convert to UTC
dt_local = ChronoUtils.from_utc(dt_utc, pytz.timezone('Europe/Sofia'))  # Convert back

5. ISO Format

dt = ChronoUtils.parse_iso("2025-06-07T14:15:00")
iso_str = ChronoUtils.to_iso(dt)

6. Day/Week Boundaries

today = datetime.date.today()
start_day, end_day = ChronoUtils.get_day_bounds(today)
start_week, end_week = ChronoUtils.get_week_bounds(today, start_of_week=0)  # Monday

7. Add/Subtract Weeks, Months, Years

from django_chrono import ChronoUtils

dt = datetime.date(2025, 6, 7)
dt_plus_2w = ChronoUtils.add_weeks(dt, 2)   # +2 weeks
dt_minus_1m = ChronoUtils.sub_months(dt, 1) # -1 month
dt_plus_3y = ChronoUtils.add_years(dt, 3)   # +3 years

8. Calculate Difference

d1 = datetime.date(2024, 6, 7)
d2 = datetime.date(2025, 6, 7)
w_diff = ChronoUtils.diff_in_weeks(d2, d1)    # 52
m_diff = ChronoUtils.diff_in_months(d2, d1)   # 12
y_diff = ChronoUtils.diff_in_years(d2, d1)    # 1

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

django_chrono-0.0.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

django_chrono-0.0.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file django_chrono-0.0.2.tar.gz.

File metadata

  • Download URL: django_chrono-0.0.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for django_chrono-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a3265c6e0ee8dbc76c1ec1eab8466d7a37a615cf9f7cda3b2987f50a36e043ea
MD5 a7f062621718f08e2149220e9fed0c21
BLAKE2b-256 c8f29c5b5ecd1370b5a72f4f44b4796fd580fcff814274271a1c8306948891f1

See more details on using hashes here.

File details

Details for the file django_chrono-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: django_chrono-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for django_chrono-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 60b3c16d1f20ee8ec51e0cace96c741d0aff8aa6a6b91f78ad56e798eefcde64
MD5 ecfaa51968bee841aae1267bd6cc932f
BLAKE2b-256 107bdefd7d7e7bd6c2643f43529f7adeb7f7c0a81c27730a8c2b87e2545f64ad

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