Skip to main content

A simple and efficient library for seamless time zone conversions — with built-in batch processing for handling multiple datetime objects effortlessly.

Project description

easytz

easytz is a simple and efficient Python library for seamless time zone conversions and batch processing of datetime objects. Whether you're converting individual datetime objects across different time zones or handling multiple datetime conversions in one go, easytz makes it fast and straightforward.

Features

  • Convert a single datetime object between any two time zones.
  • Batch convert a list of datetimes from their respective time zones to a target time zone.
  • Batch conversion to multiple time zones from a single datetime object.
  • Localize a naive datetime to the system's local time zone.

Installation

To install Easytz, simply use pip:

pip install easytz

Usage Examples

1. Convert a single datetime object between two time zones

from datetime import datetime
import pytz
from easytz.convert import convert_time

# Create a timezone-aware datetime object
from_tz = 'America/New_York'
dt = datetime(2024, 10, 25, 12, 0, 0, tzinfo=pytz.timezone(from_tz))

# Convert to another time zone (only provide the target timezone)
to_tz = 'Europe/London'
converted_time = convert_time(dt, to_tz=to_tz)  # No need to pass from_tz

# Print the result
print(converted_time)  # Output: 2024-10-25 17:00:00+01:00

2. Batch convert a single datetime to multiple time zones

from easytz.convert import batch_convert_to_multiple_timezones
from datetime import datetime
import pytz

# Event time in UTC
event_time = datetime(2024, 10, 25, 15, 0, 0, tzinfo=pytz.UTC)

# List of time zones to convert to
target_timezones = ['America/New_York', 'Europe/London', 'Asia/Tokyo', 'Australia/Sydney']

# Convert the event time to all these time zones
converted_times = batch_convert_to_multiple_timezones(event_time, target_timezones)

# Print the results
for time_data in converted_times:
    print(f"Event time in {time_data['to_tz']}: {time_data['converted_time']}")

3. Batch convert a list of datetimes to a target time zone

from easytz.convert import batch_convert_times

# List of datetime objects from different time zones
times_list = [
    {'time': '2024-10-25 12:00:00', 'from_tz': 'America/New_York'},
    {'time': '2024-10-25 12:00:00', 'from_tz': 'Europe/London'}
]

# The target time zone you want to convert all times to
target_timezone = 'Asia/Tokyo'

converted_times = batch_convert_times(times_list, target_timezone)
print(converted_times)

4. Localize a naive datetime to the system's local time zones

from easytz.convert import localize_to_system_timezone

dt = datetime(2024, 10, 25, 12, 0)  # Naive datetime
localized_dt = localize_to_system_timezone(dt)
print(localized_dt)

Contributing to easytz

Contributions to easytz are welcome! Whether you're fixing a bug, adding a feature, or improving documentation, your help is appreciated.

How to Contribute

  1. Fork the Repository:
    Start by forking the easytz repository.

  2. Make Your Changes:
    Make the necessary changes, whether it's fixing a bug, adding a new feature, or improving documentation.

  3. Submit a Pull Request:
    Once your changes are ready, submit a pull request with a clear description of what you've done. Be sure to include relevant details, such as any bugs fixed or features added.

Code of Conduct

By contributing, you agree to follow the Code of Conduct, ensuring a positive environment for all.


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

easytz-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

easytz-0.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file easytz-0.1.1.tar.gz.

File metadata

  • Download URL: easytz-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for easytz-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7f28947d0e27d2e74c529c55f313f57d0c8529a7cad25d5de1efa9e59090d6e5
MD5 14fbf2060a0c7f4fc838c13bab3c6b45
BLAKE2b-256 5a0a89d7ea758ccfb3f16e3d299e6cf0623367e37555d8d64219896283ca5416

See more details on using hashes here.

File details

Details for the file easytz-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: easytz-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for easytz-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4791f8956844fcb21665327d0de76907fab917343994348926e9bf4061bd6eb4
MD5 548705d528ab1d10cef28e03cf5e8da6
BLAKE2b-256 d49d3161e886e432db8976fce035e42933d2f4815fa3c97c2109910657e5111f

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