eones.core package¶
core.__init__.py
Submodules¶
eones.core.date module¶
core.date.py
- class eones.core.date.Date(dt: datetime | None = None, tz: str | None = 'UTC', naive: Literal['utc', 'local', 'raise'] = 'raise')¶
Bases:
objectTime manipulation wrapper for timezone-aware datetime operations.
- property as_local: datetime¶
Return the datetime converted to the system’s local timezone.
- as_utc() datetime¶
Convert to UTC timezone.
- Returns:
Datetime in UTC.
- Return type:
datetime
- as_zone(zone: str) datetime¶
Convert to a specific timezone.
- Parameters:
zone (str) – Target timezone name.
- Returns:
Datetime in the new timezone.
- Return type:
datetime
- property day: int¶
Day component of the date.
- days_until(other: Date) int¶
Return the number of days until
other.Positive if
otheris later; negative if earlier.
- diff(other: Date, unit: Literal['days', 'weeks', 'months', 'years'] = 'days') int¶
Return the absolute difference in the specified unit.
- diff_for_humans(other: Date | None = None, locale: str = 'en') str¶
Return a human-readable difference between two dates.
- end_of(unit: Literal['year', 'month', 'week', 'day', 'hour', 'minute', 'second']) Date¶
Returns the datetime aligned to the end of the given unit.
- Parameters:
unit (Literal) – Temporal unit.
- Returns:
Aligned datetime.
- Return type:
- end_of_month() Date¶
Return a new Date instance representing the last moment of the current month (23:59:59.999999 UTC).
- floor(unit: Literal['year', 'month', 'week', 'day', 'hour', 'minute', 'second']) Date¶
Return a new Date aligned to the start of the given unit.
- format(fmt: str) str¶
Return formatted datetime as a string.
- classmethod from_iso(iso_str: str, tz: str | None = 'UTC') Date¶
Create a Date from an ISO 8601 string.
- classmethod from_timezone_aware_datetime(dt: datetime) Date¶
Create a Date from a timezone-aware datetime, preserving the timezone.
This is an internal method to handle timezone-aware datetimes without accessing protected members directly.
- Parameters:
dt – A timezone-aware datetime object
- Returns:
A Date instance preserving the original timezone
- Return type:
- classmethod from_unix(timestamp: float, tz: str | None = 'UTC') Date¶
Create a Date from a Unix timestamp.
- Parameters:
timestamp (float) – Seconds since epoch.
tz (str, optional) – Timezone. Defaults to “UTC”.
- Returns:
Parsed Date.
- Return type:
- property hour: int¶
Hour component of the date.
- is_between(start: datetime, end: datetime, inclusive: bool = True) bool¶
Check if date is between two datetime bounds.
- Parameters:
start (datetime) – Start datetime.
end (datetime) – End datetime.
inclusive (bool) – Include boundaries. Defaults to True.
- Returns:
True if in range.
- Return type:
bool
- is_friday() bool¶
Return True if the current date is a Friday.
- Returns:
True if the date is Friday, False otherwise.
- Return type:
bool
- is_leap_year() bool¶
Return True if the current year is a leap year.
- Returns:
True if the year is a leap year, False otherwise.
- Return type:
bool
- is_monday() bool¶
Return True if the current date is a Monday.
- Returns:
True if the date is Monday, False otherwise.
- Return type:
bool
- is_same_week(other: Date) bool¶
Check if two dates fall in the same ISO calendar week.
- Parameters:
other (Date) – Date to compare.
- Returns:
True if both dates share the same ISO week.
- Return type:
bool
- is_saturday() bool¶
Return True if the current date is a Saturday.
- Returns:
True if the date is Saturday, False otherwise.
- Return type:
bool
- is_sunday() bool¶
Return True if the current date is a Sunday.
- Returns:
True if the date is Sunday, False otherwise.
- Return type:
bool
- is_thursday() bool¶
Return True if the current date is a Thursday.
- Returns:
True if the date is Thursday, False otherwise.
- Return type:
bool
- is_tuesday() bool¶
Return True if the current date is a Tuesday.
- Returns:
True if the date is Tuesday, False otherwise.
- Return type:
bool
- is_wednesday() bool¶
Return True if the current date is a Wednesday.
- Returns:
True if the date is Wednesday, False otherwise.
- Return type:
bool
- is_weekend() bool¶
Return True if the current date falls on a weekend (Saturday or Sunday).
- Returns:
True if the date is Saturday (5) or Sunday (6), False otherwise.
- Return type:
bool
- is_within(other: Date, check_month: bool = True) bool¶
Check if the current date is within the same year/month as another Date.
- Parameters:
other (Date) – Date to compare.
check_month (bool) – If True, also check that months match.
- Returns:
True if within the same period.
- Return type:
bool
- property microsecond: int¶
Microsecond component of the date.
- property minute: int¶
Minute component of the date.
- property month: int¶
Month component of the date.
- month_span_to(other: Date) int¶
Return the number of full calendar months between self and other. Positive if other is later. Negative if other is earlier.
- next_weekday(weekday: int) Date¶
Return the next date matching the specified weekday.
- Parameters:
weekday (int) – Target weekday (0 = Monday).
- Returns:
The next date matching the weekday.
- Return type:
- classmethod now(tz: str = 'UTC', naive: Literal['utc', 'local', 'raise'] = 'raise') Date¶
Create a Date for the current moment.
- previous_weekday(weekday: int) Date¶
Return the previous date matching the specified weekday.
- Parameters:
weekday (int) – Target weekday (0 = Monday).
- Returns:
The previous date matching the weekday.
- Return type:
- replace(tz: str | None = None, naive: Literal['utc', 'local', 'raise'] | None = None, **kwargs: Any) Date¶
Return a new Date with specific fields replaced.
- property second: int¶
Second component of the date.
- start_of(unit: Literal['year', 'month', 'week', 'day', 'hour', 'minute', 'second']) Date¶
Returns the datetime aligned to the start of the given unit.
- Parameters:
unit (Literal) – Temporal unit.
- Returns:
Aligned datetime.
- Return type:
- property timezone: str¶
Return the key of the timezone in use.
- to_datetime() datetime¶
Return the internal datetime object.
- Returns:
The timezone-aware datetime.
- Return type:
datetime
- to_dict() dict¶
Return a dictionary representation of the Date.
- to_iso() str¶
Return ISO 8601 formatted string of the datetime.
- Returns:
ISO format datetime string.
- Return type:
str
- to_unix() float¶
Return Unix timestamp of the datetime.
- Returns:
Unix timestamp.
- Return type:
float
- property year: int¶
Year component of the date.
eones.core.delta module¶
core.delta.py
- class eones.core.delta.Delta(**kwargs: int)¶
Bases:
objectRepresents a compound time delta composed of calendar (years, months) and duration (weeks, days, hours, minutes, seconds) components.
Calendar components are applied first, followed by duration components. This order preserves intuitive behavior when transitioning across irregular month lengths (e.g., Jan 31 + 1 month → Feb 28/29).
Examples
>>> Delta(years=1, days=3) >>> Delta.from_iso("P1Y3D")
Notes
The original input dictionary is preserved for accurate inversion and scaling.
- apply(date: Date, calendar: bool = True, duration: bool = True) Date¶
Apply this delta to a Date instance.
- classmethod from_iso(iso: str) Delta¶
Parse ISO 8601 delta string.
- Parameters:
iso (str) – ISO-compliant duration string.
- Returns:
Parsed instance.
- Return type:
- Raises:
ValueError – If the format is invalid.
- is_zero() bool¶
Check if the delta has no effect.
- Returns:
True if delta is zero.
- Return type:
bool
- scale(factor: int) Delta¶
Multiply the delta by a scalar.
- Parameters:
factor (int) – Scaling multiplier.
- Returns:
A new instance.
- Return type:
- to_dict() Dict[str, int]¶
Return a normalized dict combining calendar and duration.
- Returns:
Keys include ‘years’, ‘months’, ‘days’, ‘hours’, etc.
- Return type:
Dict[str, int]
- to_input_dict() Dict[str, int]¶
Return the original input dictionary.
- Returns:
User-specified delta components.
- Return type:
Dict[str, int]
- to_iso() str¶
Return ISO 8601-compliant string representation.
- Returns:
Serialized delta (e.g., ‘P1Y2M3DT4H30M’).
- Return type:
str
- property total_months: int¶
Return the calendar component expressed as total months.
- property total_seconds: int¶
Return the duration component expressed as total seconds.
eones.core.delta_calendar module¶
core.calendar.py
- class eones.core.delta_calendar.DeltaCalendar(years: int = 0, months: int = 0)¶
Bases:
objectRepresents calendar-based deltas using months and years.
Unlike timedelta-based durations, this class handles logical time shifts such as “add 1 month” or “add 2 years”, accounting for month boundaries and varying month lengths.
Internally, it normalizes the delta into absolute months and reconstructs years and months from that total.
Examples
>>> DeltaCalendar(years=1, months=2) >>> DeltaCalendar.from_iso("P1Y2M")
Notes
The day component of the input datetime may be truncated if the target month has fewer days.
- apply(base_datetime: datetime) datetime¶
Apply the calendar delta to a datetime.
Shifts the month and year while preserving the day when possible. If the resulting month has fewer days, the day is truncated.
- Parameters:
base_datetime (datetime) – The original datetime.
- Returns:
A new datetime with the delta applied.
- Return type:
datetime
- classmethod from_iso(iso: str) DeltaCalendar¶
Parse an ISO 8601 calendar delta string.
- Parameters:
iso (str) – ISO string.
- Returns:
Parsed instance.
- Return type:
- Raises:
ValueError – If the string is not valid ISO format.
- invert() DeltaCalendar¶
Return a new DeltaCalendar with reversed direction.
- Returns:
The inverse calendar delta.
- Return type:
- is_zero() bool¶
Check if the delta represents no change.
- Returns:
True if both years and months are 0.
- Return type:
bool
- months¶
- scale(factor: int) DeltaCalendar¶
Multiply the delta by a scalar.
- Parameters:
factor (int) – Multiplier.
- Returns:
A new scaled instance.
- Return type:
- to_dict() Dict[str, int]¶
Return a normalized version of the delta.
This version reflects the internal normalized representation (e.g., years=1, months=13 → years=2, months=1).
- Returns:
Keys are “years” and “months”.
- Return type:
Dict[str, int]
- to_input_dict() Dict[str, int]¶
Return the original input as passed by the user.
- Returns:
The original unnormalized dictionary.
- Return type:
Dict[str, int]
- to_iso() str¶
Serialize to ISO 8601 calendar duration.
- Returns:
ISO representation (e.g., ‘P1Y2M’).
- Return type:
str
- property total_months: int¶
Return the delta expressed as total months.
- years¶
eones.core.delta_duration module¶
core.delta_duration.py
- class eones.core.delta_duration.DeltaDuration(**kwargs: int)¶
Bases:
objectRepresents a duration-based delta using standard time components.
This class encapsulates time intervals expressed in weeks, days, hours, minutes, and seconds. Internally, it leverages Python’s timedelta but preserves original input granularity for semantic clarity.
Examples
>>> DeltaDuration(days=2, hours=4) >>> DeltaDuration.from_iso("P1DT3H")
Notes
Zero values are excluded from internal state.
Input validation ensures only integers are accepted (not bools).
- apply(base_datetime: datetime) datetime¶
Apply the duration delta to a given datetime.
- Parameters:
base_datetime (datetime) – The base datetime to shift.
- Returns:
A new datetime offset by this delta.
- Return type:
datetime
- classmethod from_iso(iso: str) DeltaDuration¶
Parse an ISO 8601 duration string.
Supports optional weeks (e.g., ‘P2W’) as per extended ISO 8601.
- Parameters:
iso (str) – Duration in ISO 8601 format.
- Returns:
Parsed delta instance.
- Return type:
- Raises:
ValueError – If the format is invalid.
- classmethod from_timedelta(td: timedelta) DeltaDuration¶
Create a DeltaDuration from a
datetime.timedelta.
- invert() DeltaDuration¶
Return a new DeltaDuration with negated values.
- Returns:
The inverse duration.
- Return type:
- is_zero() bool¶
Check if the duration is equivalent to zero.
- Returns:
True if total time is 0 seconds.
- Return type:
bool
- scale(factor: int) DeltaDuration¶
Multiply the duration by a scalar factor.
- Parameters:
factor (int) – The scaling multiplier.
- Returns:
A new instance with scaled values.
- Return type:
- timedelta¶
- to_dict() Dict[str, int]¶
Return a normalized breakdown of the duration into explicit units.
- Returns:
Keys are days, hours, minutes, and seconds.
- Return type:
Dict[str, int]
- to_input_dict() Dict[str, int]¶
Return the original dictionary passed to the constructor.
- Returns:
User-provided keyword arguments (filtered and non-zero).
- Return type:
Dict[str, int]
- to_iso() str¶
Serialize the duration to ISO 8601 format.
- Returns:
ISO 8601-compliant duration string (e.g., ‘P1DT2H30M’).
- Return type:
str
- property total_seconds: int¶
Return the duration expressed in total seconds.
eones.core.parser module¶
core.parser.py
- class eones.core.parser.Parser(tz: str = 'UTC', formats: List[str] | None = None)¶
Bases:
objectConverts unshaped temporal input into meaningful Date form.
Accepts strings, dictionaries, datetimes, or Date instances, and interprets them based on provided format patterns. Useful for transforming loose or user-provided values into structured time representations.
eones.core.range module¶
core.range.py
- class eones.core.range.Range(date: Date)¶
Bases:
objectGenerates the start and end bounds of a temporal window.
Based on a given Date, this class exposes methods to calculate the exact datetime boundaries of days, months, and years — including edge-aligned timestamps suitable for querying, slicing, and framing temporal datasets.
- custom_range(start_delta: Delta, end_delta: Delta) Tuple[datetime, datetime]¶
Return a range defined by applying deltas to the base date.
- day_range() Tuple[datetime, datetime]¶
Return the start and end of the current day.
- Returns:
Start and end of the day.
- Return type:
Tuple[datetime, datetime]
- month_range() Tuple[datetime, datetime]¶
Return the start and end of the current month.
- Returns:
Start and end of the month.
- Return type:
Tuple[datetime, datetime]
- quarter_range() Tuple[datetime, datetime]¶
Return the start and end of the current quarter.
- Returns:
Start and end of the quarter.
- Return type:
Tuple[datetime, datetime]
- week_range(first_day_of_week: int = 0) Tuple[datetime, datetime]¶
Return the start and end of the current week.
- Parameters:
first_day_of_week (int) – First day of week (0=Monday, 6=Sunday)
- Returns:
Start and end of the week.
- Return type:
Tuple[datetime, datetime]
- year_range() Tuple[datetime, datetime]¶
Return the start and end of the current year.
- Returns:
Start and end of the year.
- Return type:
Tuple[datetime, datetime]