Skip to main content

Functional approach to dates (as ISO-DATE string)

Project description

datefun

Functional approach to date manipulations.

Date is string. In ISO format (Y-M-D). Mostly it came from database.

Now we want some manipulations and return again ISO date as string.

Conversion functions:

  • dt_make(year: int, month: int, day: int) -> str
  • dt_from_object(obj: datetime) -> str

Date (string) output functions:

  • dt_month_start(iso_date: str) -> str
  • dt_month_end(iso_date: str) -> str
  • dt_year_start(iso_date: str) -> str
  • dt_year_end(iso_date: str) -> str
  • dt_add_years(iso_date: str, many_years: int, interpret_0228_as_monthend: bool = True) -> str
  • dt_add_months(iso_date: str, many_months: int, stay_in_month_end: bool = True) -> str
  • dt_add_days(iso_date: str, many_days: int) -> str

Boolean output functions:

  • is_leap_year(year_or_date: int | str) -> bool
  • is_valid_date(iso_date: str) -> bool

Integer output functions:

  • int_days_in_month(iso_date: str) -> int

No external dependecies (only internals, eg. datetime)

Needs python 3.10 (because of type hints/annotations with pipes)

install

pip install datefun

(or pip3 or pipx)

usage

from datefun import datefun

print(datefun.dt_add_months("2025-02-28", -1)) # outputs 2025-01-31
print(datefun.dt_add_months("2025-02-28", 1, False)) # outputs 2025-03-28

or

from datefun.datefun import dt_add_months

print(dt_add_months("2025-02-28", -1)) # outputs 2025-01-31
print(dt_add_months("2025-02-28", 1, False)) # outputs 2025-03-28

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

datefun-0.0.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file datefun-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: datefun-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for datefun-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 892555d618f85214bd283e95a7abb5dd19d9fc586cf80bd920a6393e697f560b
MD5 6de937dec0511b2e90417fd230c8e568
BLAKE2b-256 25a101a19cc2459620f49887cdedfee677c0fe6a7904f8d903f62fe44cb33a0d

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