Skip to main content

Python time engine.

Project description

TimeLab

This library handles everything related to time, Heres an example of how to use this library:

from timelab import TimeSpan

timespan = TimeSpan(minutes=100)
print(timespan.seconds)  # Output: 0
print(timespan.minutes)  # Output: 100
print(timespan.hours)    # Output: 0

# Find total
print(timespan.total_seconds())  # Output: 6000
print(timespan.total_minutes())  # Output: 100
print(timespan.total_hours())    # Output: 1.6~

# Add time
print(TimeSpan(minutes=100) + TimeSpan(minutes=30))  # Output: TimeSpan(130 minutes)

# Subtract time
print(TimeSpan(minutes=100) - TimeSpan(minutes=30))  # Output: TimeSpan(70 minutes)

# Normalize time
# Normalize() will normalize the time format to make it more readable
print(TimeSpan(seconds=125).normalize())  # Output: TimeSpan(2 minutes, 5 seconds)
print(TimeSpan(hours=2.5).normalize())  # Output: TimeSpan(2 hours, 30 minutes)

# Get time as dictionary
print(TimeSpan(hours=2.5).as_dictionary())  # Output: {'hours': 2.5, 'centuries': 0.0, 'years': 0.0, ...}
print(TimeSpan(hours=2.5).as_dictionary())  # Output: {'hours': 2.5, 'centuries': 0.0, 'years': 0.0, ...}

# As datetime
print(TimeSpan(hours=2.5).as_datetime())  # Output: DateTime(2.5 hours)

And usage for datetime:

from timelab import DateTime, TimeSpan

# Timestamp
print(DateTime.now().timestamp())  # Output format: Year-Month-Day

# Timestamp with custom format
print(DateTime.now().timestamp(time_format='Year: %Y, Month: %M, Day: %D'))  # Output format: Year: Year, Month: Month, Day: Day

# As timespan
print(DateTime.now().as_timespan())

# Add and subtract timespan to datetime
print(DateTime.now() + TimeSpan(minutes=30))
print(DateTime.now() - TimeSpan(minutes=30))

# Get difference between 2 datetimes
print(DateTime.now() - DateTime.now())  # Returns the difference as a timespan

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

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

Source Distribution

timelab-1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

timelab-1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file timelab-1.0.tar.gz.

File metadata

  • Download URL: timelab-1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for timelab-1.0.tar.gz
Algorithm Hash digest
SHA256 2719ecee39dc2ac7a1c90adc523e46c189082aaa9a4ef1b0ffc9cf8da58372aa
MD5 341b378d6ffd0aef345b47f562d3fbf7
BLAKE2b-256 266babaffef399821452e7d6d3a0f52848d5dc8b1d7eb2dc4bf0fe5df8fec775

See more details on using hashes here.

File details

Details for the file timelab-1.0-py3-none-any.whl.

File metadata

  • Download URL: timelab-1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for timelab-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a296b4dcc82f21df5b81a8d398903a2a54bc15808297400f847a775b748a548d
MD5 a50363c768c546951818ae6b2a5bdb1a
BLAKE2b-256 7d94145780a2e871a9f4c90f5c5135b704a7dddb7d7a48ad8f7f894694227681

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