Skip to main content

Democritus functions for working with dates and times in Python.

Project description

Democritus Dates

PyPI CI Lint codecov The Democritus Project uses semver version 2.0.0 The Democritus Project uses ruff to format and lint code License: LGPL v3

Democritus functions[1] for working with and using dates and times.

[1] Democritus functions are simple, effective, modular, well-tested, and well-documented Python functions.

We use d8s (pronounced "dee-eights") as an abbreviation for democritus (you can read more about this here).

Installation

pip install d8s-dates

Usage

You import the library like:

from d8s_dates import *

Once imported, you can use any of the functions listed below.

Functions

  • def date_string_to_strftime_format(date_string):
        """Predict the strftime format from the given date_string."""
    
  • def date_parse(date, *, convert_to_current_timezone: bool = False):
        """Parse the given date (can parse dates in most formats) (returns a datetime object)."""
    
  • def date_now(*, convert_to_current_timezone: bool = False, utc: bool = False):
        """Get the current date.
    
    If convert_to_current_timezone is True, convert the date to the current timezone.
    If utc is True, convert the date to UTC."""
    
  • def date_parse_first_argument(func):
        """."""
    
  • def date_2_string(date, date_format_string: str):
        """."""
    
  • def date_hour(date):
        """Find the hour from the given date."""
    
  • def date_minute(date):
        """Find the minute from the given date."""
    
  • def date_second(date):
        """Find the second from the given date."""
    
  • def date_day(date):
        """Find the day of the month from the given date."""
    
  • def date_day_of_month(date):
        """Find the day of the month from the given date."""
    
  • def date_month(date):
        """Find the month from the given date."""
    
  • def date_year(date):
        """Find the year from the given date."""
    
  • def date_convert_to_timezone(date, timezone_string):
        """Convert the given date to the given timezone_string.
    
    This will actually **convert** time given date; it will change the hour/day of the date to the given timezone)."""
    
  • def date_make_timezone_aware(datetime_object, timezone_string=None):
        """Make the given datetime_object timezone aware.
    
    This function does NOT convert the datetime_object.
    It will never change the hour/day or any value of the datetime...
      it will simply make the given datetime timezone aware."""
    
  • def time_delta_examples(n=10, *, time_deltas_as_strings: bool = True):
        """Return n time deltas."""
    
  • def time_examples(n=10, *, times_as_strings: bool = True):
        """Return n times."""
    
  • def date_examples(n=10, *, dates_as_strings: bool = True, date_string_format: str = None):
        """Return n dates."""
    
  • def datetime_examples(n=10, *, datetimes_as_strings: bool = True, datetime_string_format: str = None):
        """Return n datetimes."""
    
  • def time_struct_to_datetime(struct_time_object):
        """Convert a python time.struct_time object into a datetime object."""
    
  • def epoch_time_now():
        """Get the current epoch time."""
    
  • def is_date(possible_date_string):
        """Determine if the given possible_date_string can be processed as a date."""
    
  • def time_now():
        """Return the current, epoch time."""
    
  • def time_since(date):
        """Return a time of the time since the given date."""
    
  • def time_until(date):
        """Return an English description of the time since the given date."""
    
  • def time_since_slang(date):
        """Return an English description of the time since the given date."""
    
  • def time_until_slang(date):
        """Return an English description of the time until the given date."""
    
  • def date_to_utc(date):
        """Convert the given date to UTC. Assume that the given date is in the system's timezone and convert it to UTC."""
    
  • def time_after(time_a, time_b=None) -> bool:
        """Check if one time is before the other."""
    
  • def time_before(time_a, time_b=None) -> bool:
        """Check if one time is before the other."""
    
  • def date_in_future(date) -> bool:
        """Return whether or not the given date is in the future."""
    
  • def time_is() -> str:
        """Time and money spent in helping men to do more for themselves is far better than mere giving. -Henry Ford"""
    
  • def date_to_iso(date, *, timezone_is_utc: bool = False, use_trailing_z: bool = False):
        """Return the ISO 8601 version of the given date as a string (see https://en.wikipedia.org/wiki/ISO_8601)."""
    
  • def epoch_time_standardization(epoch_time):
        """Convert the given epoch time to an epoch time in seconds."""
    
  • def epoch_to_date(epoch_time):
        """Convert the epoch_time into a datetime."""
    
  • def date_day_of_week(date):
        """Return the day of the week on which the given date occurred."""
    
  • def date_week_of_year(date, *, sunday_is_first_day_of_week: bool = False):
        """Find the week of the year for the given date. If no date is given, return the week of the current date."""
    
  • def date_to_epoch(date):
        """Convert a datetime stamp to epoch time."""
    
  • def chrome_timestamp_to_epoch(chrome_timestamp):
        """Convert the given Chrome timestamp to epoch time.
    
    For more information, see: https://stackoverflow.com/questions/20458406/what-is-the-format-of-chromes-timestamps."""
    
  • def time_waste(n=3):
        """If time be of all things the most precious, wasting time must be the greatest prodigality. -Benjamin Franklin"""
    
  • def time_as_float(time_string: str) -> float:
        """converts a given HH:MM time string to float"""
    

Development

👋  If you want to get involved in this project, we have some short, helpful guides below:

If you have any questions or there is anything we did not cover, please raise an issue and we'll be happy to help.

Credits

This package was created with Cookiecutter and Floyd Hightower's Python project template.

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

d8s_dates-0.8.0.tar.gz (118.7 kB view details)

Uploaded Source

Built Distribution

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

d8s_dates-0.8.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file d8s_dates-0.8.0.tar.gz.

File metadata

  • Download URL: d8s_dates-0.8.0.tar.gz
  • Upload date:
  • Size: 118.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for d8s_dates-0.8.0.tar.gz
Algorithm Hash digest
SHA256 0510a27c7d29070fdc8bc704d2d378f46e6e615dc53afba26263dce1b0cdb424
MD5 04b6686d403fab36a353eef18221119e
BLAKE2b-256 20cc1b53a13c0868d1bfde20acd8da76e1fe69cf414bf26a965ebfefdba67579

See more details on using hashes here.

Provenance

The following attestation bundles were made for d8s_dates-0.8.0.tar.gz:

Publisher: release-please.yml on democritus-project/d8s-dates

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file d8s_dates-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: d8s_dates-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for d8s_dates-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f9e3b73f4b92769d85cb950f835161a978db8b56f744229b4b1aa77fd32c5d9
MD5 fe5f421ad3f3efcacdeacddf6219135b
BLAKE2b-256 7081174755712c1bf99b176731d80328e71289880a63fa6c89dd9d18085963f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for d8s_dates-0.8.0-py3-none-any.whl:

Publisher: release-please.yml on democritus-project/d8s-dates

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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