diti to reduce your datetime operation pains
Project description
diti - Reduce Your Datetime Operation Pains
Introduction
diti is a powerful and user-friendly Python library that simplifies datetime operations, aiming to reduce your datetime-related headaches. With diti, you can perform a wide range of datetime tasks with ease and precision, allowing you to focus on the core functionality of your projects rather than wrestling with date and time intricacies.
Installation
You can install diti using pip:
pip install diti
Features
1. Diti Object > mutable
The Diti Object is a powerful feature of the diti
library that enhances your datetime manipulation capabilities. With the Diti Object, you can:
- Flexible Constructor The Diti Object constructor accepts various input formats, including floats, ISO 8601 strings, and standard datetime objects, providing flexibility and compatibility for your specific needs.
from diti import Diti
from datettime import datetime
dt_now = Diti()
dt1 = Diti("2023-01-01")
dt2 = Diti("2023-01-01T00:00:00.000+0300")
dt3 = Diti(datetime.now())
dt4 = Diti(1697277012)
dt5 = Diti("2023-01-01T00:00:00", timezone="+0300")
dt6 = Diti("2023-01-01T00:00:00", timezone="Europe/Istanbul")
dt7 = Diti("2023-01-01T00:00:00", timezone=180)
- Save Your DateTime Object Mutably Preserve your datetime object while making changes with ease.
diti
allows you to update the object seamlessly, ensuring your data remains mutable.
from diti import Diti, DitiParts
dt = Diti()
dt.edit().add(DitiParts.HOURS, 1).commit()
another_dt = dt_now().clone()
another_dt.edit().head_of(DitiParts.DAYS)
- Elegant Operational Functions: Perform datetime operations elegantly, simplifying complex tasks.
diti
offers a wide array of intuitive methods to modify and manipulate your datetime object effortlessly.
from diti import Diti, DitiParts, DitiTimezone, DitiOps
dt1 = Diti()
(dt1.edit()
.timezone_change(DitiTimezone.EUROPE__ISTANBUL)
.tail_of(DitiParts.MONTHS)
.head_of(DitiParts.WEEK)
.commit()
)
dt2 = Diti()
dt2.edit_ops([
DitiOps.TZ_CHANGE(DitiTimezone.EUROPE_ISTANBUL),
DitiOps.TAIL_OF(DitiParts.MONTHS),
DitiOps.HEAD_OF(DitiParts.WEEK)
])
The Diti Object empowers you to work with datetime data in a manner that is both flexible and user-friendly, reducing the complexities of datetime operations.
2. diti_op > immutable
The diti_op feature is a versatile component of the diti
library, designed to make working with datetime objects a breeze. With diti_op, you can:
- Immutable DateTime Object Support: Whether you prefer to use immutable
datetime.datetime
objects or mutable ones, diti_op provides full functionality. It seamlessly accommodates your choice, ensuring you can work with datetime data as you like.
from datetime import datetime
from diti import diti_op, DitiOps, DitiParts
dt = datetime.now()
tomorrow = diti_op(dt, [
DitiOps.ADD(DitiParts.DAYS, 1)
])
- Flexible Initialization: DITI_OP allows you to initialize your datetime objects using a variety of formats, including floats, ISO 8601 strings, or standard datetime objects. This flexibility makes it effortless to create datetime instances that suit your specific requirements.
from datetime import datetime
from diti import diti_op, DitiOps, DitiParts
tomorrow = diti_op(datetime.now(), [
DitiOps.ADD(DitiParts.DAYS, 1)
])
previous_day = diti_op("2023-01-01T12:34",[
DitiOps.ADD(DitiParts.DAYS, -1)
])
end_of_week = diti_op(1697277012,[
DitiOps.TAIL_OF(DitiParts.WEEK)
])
- Effortless Object Updates: diti_op simplifies the process of modifying your datetime objects. Its intuitive methods enable easy updates, making it convenient to perform various datetime operations without unnecessary complexity.
from datetime import datetime
from diti import diti_op, DitiOps, DitiParts
dt = diti_op(datetime.now(), [
DitiOps.TZ_UPDATE(DitiTimezone.EUROPE_ISTANBUL),
DitiOps.TAIL_OF(DitiParts.MONTHS),
DitiOps.HEAD_OF(DitiParts.WEEK)
])
diti_op is your trusted companion for datetime management, offering adaptability, ease of use, and efficient datetime object handling.
3. diti_interval
The diti_interval feature is a powerful addition to the DITI library, built to simplify interval-based datetime operations. With diti_interval, you can:
Seamlessly handle a wide range of interval-based datetime operations with ease. diti_interval streamlines the process, allowing you to work with date and time intervals in a straightforward manner.
- Find Closest Datetime: Quickly identify the closest datetime within a list of datetime instances. This feature is incredibly useful for locating the nearest reference point in your datetime data.
from diti import diti_interval
from datetime import datetime
closest_index = diti_interval.closest_time(
datetime.fromtimestamp(5),
[
datetime.fromtimestamp(1),
datetime.fromtimestamp(2),
datetime.fromtimestamp(3),
datetime.fromtimestamp(6),
datetime.fromtimestamp(7)
]
)
- Divide DateTime Ranges into Slots: Divide a datetime range into discrete slots, enabling you to categorize and organize your data with precision. This is particularly valuable when dealing with scheduling, time management, or data segmentation.
from diti import diti_interval, DitiParts
from datetime import datetime
time_list = diti_interval.divide_into_timeslots(
datetime.fromtimestamp(5),
datetime.fromtimestamp(10),
DitiParts.SECONDS,
1
)
- Discover Overlapping Time Slots: Easily detect overlapping time slots within your data, making it simple to analyze conflicts, schedule intersections, or any scenario where overlapping time intervals need to be managed.
from diti import diti_interval
from datetime import datetime
overlapped_index_list = diti_interval.overlapped_timeslots(
datetime.fromtimestamp(5),
[
(datetime.fromtimestamp(1), datetime.fromtimestamp(5))
(datetime.fromtimestamp(2), datetime.fromtimestamp(10))
(datetime.fromtimestamp(4), datetime.fromtimestamp(15))
(datetime.fromtimestamp(3), None)
(None, datetime.fromtimestamp(7))
]
)
diti_interval empowers you to work with datetime intervals, providing a set of tools that simplify complex operations and streamline your datetime-based workflows.
Contact
Have questions, suggestions, or need support? Reach out to me at mujdecisy@gmail.com
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
File details
Details for the file diti-0.0.7.tar.gz
.
File metadata
- Download URL: diti-0.0.7.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 047dcc1d72f10b51792c518ae770b0a6e3721f15ce492f5056663e9da36f1f92 |
|
MD5 | a2143c0fec95c5fccbac819cc8334174 |
|
BLAKE2b-256 | f14c57bace1a6e5ad3d758f1e0066167fa790cc7d39ed67d7b860f1cbc31b39d |