date_evaluations¶
shortfx.fxDate.date_evaluations
¶
Date evaluation functions.
This module provides utility functions for validating and checking date-related types and temporal properties such as past, future, and same-day comparisons.
Functions¶
age_at_date(birth_date: Union[datetime, date], reference: Union[datetime, date, None] = None) -> int
¶
Calculate age in complete years at a reference date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
birth_date
|
Union[datetime, date]
|
Date of birth. |
required |
reference
|
Union[datetime, date, None]
|
Reference date (default: today). |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Age in complete years. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not date or datetime. |
ValueError
|
If birth_date is in the future relative to reference. |
Example
from datetime import date age_at_date(date(1990, 6, 15), date(2025, 6, 14)) 34 age_at_date(date(1990, 6, 15), date(2025, 6, 15)) 35
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
astronomical_season(d: date | datetime, hemisphere: str = 'north') -> str
¶
Determine the astronomical season based on equinox/solstice dates.
Uses approximate fixed dates for equinoxes and solstices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
date | datetime
|
Date to evaluate. |
required |
hemisphere
|
str
|
|
'north'
|
Returns:
| Type | Description |
|---|---|
str
|
Season name: |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date/datetime. |
ValueError
|
If hemisphere is invalid. |
Example
from datetime import date astronomical_season(date(2026, 7, 15)) 'summer' astronomical_season(date(2026, 7, 15), "south") 'winter'
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
bimester_of_date(d: Union[datetime, date]) -> int
¶
Return the bimester number for a date.
A bimester is a two-month period. Jan–Feb → 1, Mar–Apr → 2, …, Nov–Dec → 6.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Bimester number (1–6). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date bimester_of_date(date(2025, 5, 10)) 3
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
century_of_date(d: Union[datetime, date]) -> int
¶
Return the century number of a date.
The 21st century covers years 2001-2100.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Century number (e.g. 21 for year 2025). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date century_of_date(date(2025, 6, 15)) 21
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
chinese_zodiac(year: int) -> str
¶
Returns the Chinese zodiac animal for a given year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
A calendar year (e.g. 2024). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Animal name in English (e.g. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If year is not an integer. |
Example
chinese_zodiac(2024) 'Dragon'
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
date_grade(d) -> str
¶
Classify a date into a period label: 'ancient', 'medieval', 'modern', or 'contemporary'.
Uses simplified thresholds: - ancient: before 476 AD - medieval: 476–1453 - modern: 1453–1945 - contemporary: 1945+
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Date to classify (date or datetime). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Period label string. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date/datetime. |
Example
from datetime import date date_grade(date(2024, 1, 1)) 'contemporary'
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
date_of_easter(year: int) -> date
¶
Calculate the date of Easter Sunday using the Anonymous Gregorian algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Gregorian calendar year (≥ 1583). |
required |
Returns:
| Type | Description |
|---|---|
date
|
Date of Easter Sunday. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If year is not an integer. |
ValueError
|
If year < 1583. |
Example
date_of_easter(2025) datetime.date(2025, 4, 20)
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
date_of_nth_weekday(year: int, month: int, weekday: int, n: int) -> datetime
¶
Return the date of the n-th occurrence of a weekday in a month.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Calendar year. |
required |
month
|
int
|
Month (1–12). |
required |
weekday
|
int
|
Day of the week (0 = Monday … 6 = Sunday). |
required |
n
|
int
|
Occurrence number (1 = first, 2 = second, …). |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
A datetime for the requested date. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any argument is not an integer. |
ValueError
|
If parameters are out of range or the n-th occurrence does not exist in the month. |
Example
date_of_nth_weekday(2025, 11, 3, 4) datetime.datetime(2025, 11, 27, 0, 0)
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 | |
date_to_julian_day(d: Union[datetime, date]) -> int
¶
Return the Julian Day Number for a date.
Uses the algorithm for the proleptic Gregorian calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Julian Day Number as an integer. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date date_to_julian_day(date(2000, 1, 1)) 2451545
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
day_name_of_date(d: Union[datetime, date]) -> str
¶
Return the English weekday name for a date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Weekday name (e.g. "Monday"). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date day_name_of_date(date(2025, 4, 20)) 'Sunday'
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
days_in_year(year: int) -> int
¶
Return the number of days in a given year (365 or 366).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Calendar year. |
required |
Returns:
| Type | Description |
|---|---|
int
|
365 for common years, 366 for leap years. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If year is not an integer. |
Example
days_in_year(2024) 366 days_in_year(2025) 365
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
days_until_end_of_year(d: Union[datetime, date]) -> int
¶
Return the number of days remaining until the end of the year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of remaining days (31 Dec → 0). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date days_until_end_of_year(date(2025, 12, 1)) 30
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
days_until_next_birthday(birth_date: Union[datetime, date], reference: Union[datetime, date, None] = None) -> int
¶
Calculate the number of days until the next birthday.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
birth_date
|
Union[datetime, date]
|
The person's date of birth. |
required |
reference
|
Union[datetime, date, None]
|
Reference date (default: today). |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Days remaining until the next birthday (0 if today is the birthday). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not date or datetime. |
Example
from datetime import date days_until_next_birthday(date(1990, 6, 15), date(2025, 6, 10)) 5
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
days_until_weekday(d, target_weekday: int) -> int
¶
Return the number of days from d until the next occurrence of target_weekday.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Starting date (date or datetime). |
required | |
target_weekday
|
int
|
ISO weekday (1=Monday … 7=Sunday). |
required |
Returns:
| Type | Description |
|---|---|
int
|
Days until next occurrence (0 if d is already that weekday). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date/datetime. |
ValueError
|
If target_weekday is not 1–7. |
Example
from datetime import date days_until_weekday(date(2024, 1, 1), 5) 4
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
elapsed_years(start: Union[datetime, date], end: Union[datetime, date]) -> int
¶
Return the number of full years between two dates.
A "full year" means the anniversary date has been reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
Union[datetime, date]
|
Start date. |
required |
end
|
Union[datetime, date]
|
End date (must be ≥ start). |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of complete years as an integer. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If start or end is not a date or datetime. |
ValueError
|
If end is before start. |
Example
from datetime import date elapsed_years(date(2000, 6, 15), date(2025, 4, 8)) 24
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
fiscal_quarter(d: Union[datetime, date], fiscal_start_month: int = 1) -> int
¶
Return the fiscal quarter (1-4) for a given date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
fiscal_start_month
|
int
|
Month when the fiscal year starts (1-12, default 1 = Jan). |
1
|
Returns:
| Type | Description |
|---|---|
int
|
Fiscal quarter number (1-4). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
ValueError
|
If fiscal_start_month is not between 1 and 12. |
Example
from datetime import date fiscal_quarter(date(2025, 3, 15)) 1 fiscal_quarter(date(2025, 3, 15), fiscal_start_month=4) 4
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
fortnight_of_year(d: Union[datetime, date]) -> int
¶
Return the fortnight number of the year (1-based).
Each fortnight spans 14 days. Day 1–14 → fortnight 1, day 15–28 → fortnight 2, and so on (up to 27).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Fortnight number (1–27). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date fortnight_of_year(date(2025, 1, 15)) 2
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
generation_name(year: int) -> str
¶
Return the generational cohort name for a birth year.
Ranges (approximate, commonly used): - Silent Generation: 1928-1945 - Baby Boomers: 1946-1964 - Generation X: 1965-1980 - Millennials (Gen Y): 1981-1996 - Generation Z: 1997-2012 - Generation Alpha: 2013-2025
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Birth year. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Generation name as a string. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If year is not an integer. |
ValueError
|
If year is before 1928 or after 2025. |
Example
generation_name(1990) 'Millennial'
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_anniversary(reference: Union[datetime, date], target: Union[datetime, date]) -> bool
¶
Checks if target falls on the same month and day as reference.
Useful for detecting birthdays, founding dates, or recurring annual events regardless of year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Union[datetime, date]
|
The original date (anniversary origin). |
required |
target
|
Union[datetime, date]
|
The date to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if month and day match, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not date/datetime objects. |
Example
from datetime import date is_anniversary(date(1990, 7, 4), date(2026, 7, 4)) True is_anniversary(date(1990, 7, 4), date(2026, 7, 5)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_blue_moon(year: int, month: int) -> bool
¶
Check whether a given month contains a blue moon.
A blue moon is the second full moon in a calendar month. This function uses a simplified mean-synodic-month calculation (29.53 days) anchored to a known full moon (2000-01-06 18:14 UTC).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Calendar year. |
required |
month
|
int
|
Calendar month (1-12). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not integers. |
ValueError
|
If month is outside [1, 12]. |
Example
is_blue_moon(2026, 5) True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_business_hours(dt: datetime, start_hour: int = 9, end_hour: int = 17) -> bool
¶
Checks if a datetime falls within business hours on a weekday.
A datetime is considered business hours when the day is Monday–Friday
and the time is between start_hour (inclusive) and end_hour
(exclusive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime
|
The datetime to evaluate. |
required |
start_hour
|
int
|
Opening hour in 24-h format (default 9). |
9
|
end_hour
|
int
|
Closing hour in 24-h format (default 17). |
17
|
Returns:
| Type | Description |
|---|---|
bool
|
True if dt is within business hours, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If dt is not a datetime object. |
Example
from datetime import datetime is_business_hours(datetime(2026, 4, 6, 10, 30)) # Monday 10:30 True is_business_hours(datetime(2026, 4, 5, 10, 30)) # Sunday 10:30 False is_business_hours(datetime(2026, 4, 6, 18, 0)) # Monday 18:00 False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_century_year(year: int) -> bool
¶
Check if a year is a century year (divisible by 100).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Year to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if year is divisible by 100. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If year is not an integer. |
Example
is_century_year(2000) True is_century_year(2024) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_date_in_range(d, start, end) -> bool
¶
Check if a date falls within [start, end] inclusive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Date to check. |
required | |
start
|
Range start (date or datetime). |
required | |
end
|
Range end (date or datetime). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if d is in [start, end]. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not date/datetime. |
Example
from datetime import date is_date_in_range(date(2024, 6, 15), date(2024, 1, 1), date(2024, 12, 31)) True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_dateclass(p_datetime: datetime) -> bool
¶
Checks if the provided object is a datetime instance.
Description
This function validates whether the input parameter is an instance of the datetime class. It provides a simple type check for datetime objects, which is useful for input validation and type verification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_datetime
|
datetime
|
The object to check. Expected to be a datetime instance. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the object is a datetime instance, False otherwise. |
Usage Example
from datetime import datetime from shortfx.fxDate.date_evaluations import is_dateclass dt = datetime(2026, 1, 3, 10, 30, 0) is_dateclass(dt) True is_dateclass("2026-01-03") False is_dateclass(None) False
Cost: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_dst(dt: datetime, tz_name: str = 'UTC') -> bool
¶
Checks if a datetime falls within Daylight Saving Time.
Uses a simple rule-based approach for common time zones. For 'US/Eastern', 'US/Central', 'US/Mountain', 'US/Pacific': DST starts second Sunday of March at 2:00 AM, ends first Sunday of November at 2:00 AM. For 'Europe/London', 'Europe/Berlin', 'Europe/Paris', 'Europe/Madrid': DST starts last Sunday of March at 1:00 AM UTC, ends last Sunday of October at 1:00 AM UTC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime
|
The datetime to check (naive; interpreted in the named zone). |
required |
tz_name
|
str
|
Time zone identifier. |
'UTC'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the datetime is within DST, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If dt is not a datetime. |
ValueError
|
If tz_name is not supported. |
Example
from datetime import datetime is_dst(datetime(2026, 7, 15, 12, 0), "US/Eastern") True is_dst(datetime(2026, 1, 15, 12, 0), "US/Eastern") False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_dst_transition_day(d: Union[date, datetime], tz_name: str) -> bool
¶
Returns True if the given date has a DST (Daylight Saving Time) transition.
Checks whether the UTC offset changes between the start and end of the day in the specified timezone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[date, datetime]
|
The date to check. |
required |
tz_name
|
str
|
IANA timezone name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if a DST transition occurs on that day. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date/datetime or tz_name is not a string. |
ValueError
|
If tz_name is not a valid timezone. |
Example
from datetime import date is_dst_transition_day(date(2026, 3, 29), "Europe/Madrid") True is_dst_transition_day(date(2026, 6, 15), "Europe/Madrid") False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_end_of_month(d: Union[datetime, date]) -> bool
¶
Check if a date is the last day of its month.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if d is the last day of its month. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_end_of_month(date(2025, 2, 28)) True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_end_of_quarter(d: Union[datetime, date]) -> bool
¶
Check if a date falls on the last day of a calendar quarter.
Quarter end dates: Mar 31, Jun 30, Sep 30, Dec 31.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if d is the last day of a quarter. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_end_of_quarter(date(2024, 3, 31)) True is_end_of_quarter(date(2024, 4, 15)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_equinox_or_solstice(d: date | datetime) -> str | None
¶
Return the astronomical event name if d falls on one, else None.
Uses approximate fixed dates for the Northern Hemisphere: - March 20: vernal equinox - June 21: summer solstice - September 22: autumnal equinox - December 21: winter solstice
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
date | datetime
|
Date to check. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Name of the event or |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_equinox_or_solstice(date(2026, 6, 21)) 'summer_solstice'
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_first_day_of_month(d: Union[datetime, date]) -> bool
¶
Check if a date is the first day of its month.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if d is the 1st of its month. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_first_day_of_month(date(2025, 6, 1)) True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_first_of_month(d: Union[datetime, date]) -> bool
¶
Check if a date falls on the first day of the month.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if d is the first day of the month. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_first_of_month(date(2024, 1, 1)) True is_first_of_month(date(2024, 1, 15)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_friday_13th(d: date | datetime) -> bool
¶
Check whether a date falls on Friday the 13th.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
date | datetime
|
Date to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_friday_13th(date(2026, 2, 13)) True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_future(date_input: Union[datetime, date]) -> bool
¶
Checks if a date is strictly in the future.
Description
Returns True when date_input is later than the current date/time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_input
|
Union[datetime, date]
|
The date or datetime to evaluate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the date is in the future, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If date_input is not a date or datetime. |
Example
from datetime import datetime is_future(datetime(2099, 12, 31)) True is_future(datetime(2020, 1, 1)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_golden_hour(d: datetime, latitude: float, longitude: float) -> bool
¶
Approximate whether a datetime falls within the golden hour.
Golden hour is roughly the first/last hour of sunlight. Uses a simplified sunrise/sunset calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
datetime
|
Datetime to check (should include time component). |
required |
latitude
|
float
|
Latitude in decimal degrees. |
required |
longitude
|
float
|
Longitude in decimal degrees. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a datetime. |
ValueError
|
If latitude/longitude out of range. |
Example
from datetime import datetime is_golden_hour(datetime(2026, 6, 21, 6, 30), 40.0, -3.7) True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 | |
is_holiday(d: date | datetime, country: str = 'ES') -> bool
¶
Check if a date is a public holiday in the given country.
Supports simplified holiday sets for ES, US, GB, FR, DE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
date | datetime
|
Date to check. |
required |
country
|
str
|
ISO 3166-1 alpha-2 country code. |
'ES'
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date/datetime. |
ValueError
|
If country is not supported. |
Example
from datetime import date is_holiday(date(2026, 12, 25), "ES") True is_holiday(date(2026, 4, 8), "ES") False
Complexity: O(H), H = holidays in the country.
Source code in shortfx/fxDate/date_evaluations.py
is_iso_long_year(year: int) -> bool
¶
Check if an ISO year has 53 weeks.
Description
An ISO year has 53 weeks when December 31 of the Gregorian year or January 1 of the next year falls in ISO week 53. Equivalent to checking that the Gregorian year starts on Thursday, or is a leap year starting on Wednesday.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The ISO year to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the ISO year has 53 weeks (a "long" ISO year). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If year is not an integer. |
Usage Example
is_iso_long_year(2020) True is_iso_long_year(2023) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_last_day_of_month(d: Union[datetime, date]) -> bool
¶
Checks if a date is the last day of its month.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
The date to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if d is the last day of its month, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_last_day_of_month(date(2024, 2, 29)) True is_last_day_of_month(date(2024, 2, 28)) False is_last_day_of_month(date(2023, 2, 28)) True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_last_day_of_year(d: Union[datetime, date]) -> bool
¶
Check if a date is December 31st.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if d is December 31. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_last_day_of_year(date(2025, 12, 31)) True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_millennium_year(year: int) -> bool
¶
Check if a year is a millennium year (divisible by 1000).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Year to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if year is divisible by 1000. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If year is not an integer. |
Example
is_millennium_year(2000) True is_millennium_year(2024) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_nth_weekday(d, n: int, weekday: int) -> bool
¶
Check if d is the n-th occurrence of a weekday in its month.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Date to check (date or datetime). |
required | |
n
|
int
|
Which occurrence (1 = first, 2 = second, etc.). |
required |
weekday
|
int
|
ISO weekday (1=Monday … 7=Sunday). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if d is the n-th weekday in its month. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date/datetime. |
ValueError
|
If n < 1 or weekday not 1–7. |
Example
from datetime import date is_nth_weekday(date(2024, 1, 8), 2, 1) True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_palindrome_date(d: Union[datetime, date]) -> bool
¶
Check if a date is a palindrome in YYYYMMDD format.
A palindrome date reads the same forwards and backwards, e.g. 2021-12-02 → "20211202" is a palindrome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the YYYYMMDD string is a palindrome. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_palindrome_date(date(2021, 12, 2)) True is_palindrome_date(date(2024, 1, 1)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_past(date_input: Union[datetime, date]) -> bool
¶
Checks if a date is strictly in the past.
Description
Returns True when date_input is earlier than the current date/time.
For date objects the comparison is date-only; for datetime
objects it includes the time component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_input
|
Union[datetime, date]
|
The date or datetime to evaluate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the date is in the past, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If date_input is not a date or datetime. |
Example
from datetime import datetime, date, timedelta is_past(datetime(2020, 1, 1)) True is_past(datetime(2099, 12, 31)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_same_day(date1: Union[datetime, date], date2: Union[datetime, date]) -> bool
¶
Checks if two dates fall on the same calendar day.
Description
Compares only the date portion of both inputs, ignoring time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date1
|
Union[datetime, date]
|
First date or datetime. |
required |
date2
|
Union[datetime, date]
|
Second date or datetime. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if both dates share the same year, month, and day. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If either argument is not a date or datetime. |
Example
from datetime import datetime is_same_day(datetime(2025, 6, 15, 8, 0), datetime(2025, 6, 15, 23, 59)) True is_same_day(datetime(2025, 6, 15), datetime(2025, 6, 16)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_same_month(date1: Union[datetime, date], date2: Union[datetime, date]) -> bool
¶
Checks if two dates fall in the same month and year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date1
|
Union[datetime, date]
|
First date or datetime. |
required |
date2
|
Union[datetime, date]
|
Second date or datetime. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if both dates share the same year and month. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If either argument is not a date or datetime. |
Example
from datetime import datetime is_same_month(datetime(2025, 6, 1), datetime(2025, 6, 30)) True is_same_month(datetime(2025, 6, 1), datetime(2025, 7, 1)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_same_quarter(date1: Union[datetime, date], date2: Union[datetime, date]) -> bool
¶
Checks if two dates fall in the same quarter and year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date1
|
Union[datetime, date]
|
First date or datetime. |
required |
date2
|
Union[datetime, date]
|
Second date or datetime. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if both dates share the same year and quarter (Q1-Q4). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If either argument is not a date or datetime. |
Example
from datetime import datetime is_same_quarter(datetime(2026, 1, 15), datetime(2026, 3, 31)) True is_same_quarter(datetime(2026, 3, 31), datetime(2026, 4, 1)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_same_week(date1: Union[datetime, date], date2: Union[datetime, date]) -> bool
¶
Checks if two dates fall in the same ISO week and year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date1
|
Union[datetime, date]
|
First date or datetime. |
required |
date2
|
Union[datetime, date]
|
Second date or datetime. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if both dates share the same ISO year and week number. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If either argument is not a date or datetime. |
Example
from datetime import datetime is_same_week(datetime(2026, 4, 6), datetime(2026, 4, 10)) True is_same_week(datetime(2026, 4, 5), datetime(2026, 4, 6)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_same_year(date1: Union[datetime, date], date2: Union[datetime, date]) -> bool
¶
Checks if two dates fall in the same year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date1
|
Union[datetime, date]
|
First date or datetime. |
required |
date2
|
Union[datetime, date]
|
Second date or datetime. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if both dates share the same year. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If either argument is not a date or datetime. |
Example
from datetime import datetime is_same_year(datetime(2025, 1, 1), datetime(2025, 12, 31)) True is_same_year(datetime(2025, 1, 1), datetime(2026, 1, 1)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_start_of_quarter(d: Union[datetime, date]) -> bool
¶
Check if a date falls on the first day of a calendar quarter.
Quarter start dates: Jan 1, Apr 1, Jul 1, Oct 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if d is the first day of a quarter. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_start_of_quarter(date(2024, 1, 1)) True is_start_of_quarter(date(2024, 2, 1)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_today(date_input: Union[datetime, date]) -> bool
¶
Checks if a date falls on today's calendar date.
Description
Compares only the date portion, ignoring any time component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_input
|
Union[datetime, date]
|
The date or datetime to evaluate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the date is today, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If date_input is not a date or datetime. |
Example
from datetime import datetime, date is_today(datetime.now()) True is_today(date(2000, 1, 1)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
is_weekday(d: Union[datetime, date]) -> bool
¶
Check if a date falls on a weekday (Monday–Friday).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the date is Monday through Friday, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date is_weekday(date(2025, 6, 9)) True is_weekday(date(2025, 6, 8)) False
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
iso_day_name(d: Union[datetime, date]) -> str
¶
Return the English name of the day of the week.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Day name (e.g. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date iso_day_name(date(2025, 6, 9)) 'Monday'
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
millennium_of_date(d: Union[datetime, date]) -> int
¶
Return the millennium number of a date.
The 3rd millennium covers years 2001-3000.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Millennium number (e.g. 3 for year 2025). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date millennium_of_date(date(2025, 1, 1)) 3
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
moon_phase(d: Union[date, datetime]) -> tuple
¶
Returns the approximate lunar phase for a given date.
Uses the Trig2 approximation based on the date's offset from a known new-moon reference (January 6, 2000).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[date, datetime]
|
The date to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (phase_ratio, phase_name) where phase_ratio is |
tuple
|
0.0–1.0 (0 ≈ new moon, 0.5 ≈ full moon) and phase_name |
tuple
|
is one of |
tuple
|
|
tuple
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date phase, name = moon_phase(date(2026, 4, 8)) 0.0 <= phase <= 1.0 True
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
next_month_same_day(d: Union[datetime, date]) -> date
¶
Return the same day number in the next month.
If the day does not exist in the next month, the last day of the next month is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
date
|
A date in the following month. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date next_month_same_day(date(2025, 1, 31)) datetime.date(2025, 2, 28)
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
nth_weekday_of_month(year: int, month: int, weekday: int, n: int) -> date
¶
Return the date of the n-th occurrence of a weekday in a month.
Useful for holidays like "3rd Monday of January" (MLK Day).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Calendar year. |
required |
month
|
int
|
Month (1-12). |
required |
weekday
|
int
|
ISO weekday (1=Monday … 7=Sunday). |
required |
n
|
int
|
Occurrence (1 = first, 2 = second, etc.). |
required |
Returns:
| Type | Description |
|---|---|
date
|
The date of the n-th weekday. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not integers. |
ValueError
|
If month, weekday, or n are out of range, or the n-th occurrence does not exist. |
Example
nth_weekday_of_month(2025, 1, 1, 3) datetime.date(2025, 1, 20)
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
ordinal_date_string(d: Union[datetime, date]) -> str
¶
Return the ISO ordinal date string for a date.
Format: "YYYY-DDD" where DDD is the day-of-year (001–366).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Ordinal date string (e.g. "2025-001"). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date ordinal_date_string(date(2025, 3, 1)) '2025-060'
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
previous_month_same_day(d: Union[datetime, date]) -> date
¶
Return the same day number in the previous month.
If the day does not exist in the previous month, the last day of the previous month is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
date
|
A date in the preceding month. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date previous_month_same_day(date(2025, 3, 31)) datetime.date(2025, 2, 28)
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
quarter_end_date(year: int, quarter: int) -> date
¶
Return the last day of a given quarter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Calendar year. |
required |
quarter
|
int
|
Quarter number (1-4). |
required |
Returns:
| Type | Description |
|---|---|
date
|
Last day of the quarter. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not integers. |
ValueError
|
If quarter not in 1-4. |
Example
quarter_end_date(2025, 1) datetime.date(2025, 3, 31)
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
quarter_start_date(year: int, quarter: int) -> date
¶
Return the first day of a given quarter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Calendar year. |
required |
quarter
|
int
|
Quarter number (1-4). |
required |
Returns:
| Type | Description |
|---|---|
date
|
First day of the quarter. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not integers. |
ValueError
|
If quarter not in 1-4. |
Example
quarter_start_date(2025, 2) datetime.date(2025, 4, 1)
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
semester_of_date(d: Union[datetime, date]) -> int
¶
Return the semester of the year for a given date.
Semester 1 covers January–June, semester 2 covers July–December.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
int
|
1 or 2. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date semester_of_date(date(2025, 3, 15)) 1
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
semester_of_year(d: Union[datetime, date]) -> int
¶
Return the semester (1 or 2) of the year.
Jan–Jun → 1, Jul–Dec → 2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
int
|
1 or 2. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date semester_of_year(date(2025, 3, 15)) 1 semester_of_year(date(2025, 9, 15)) 2
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
sidereal_time(d: Union[date, datetime], longitude: float = 0.0) -> float
¶
Approximate local sidereal time in hours.
Description
Computes Greenwich Mean Sidereal Time (GMST) at 0h UT for the given date using the IAU simplified formula, then adds the observer's longitude converted to hours.
GMST = 6.697374558 + 0.06570982441908 × D₀ where D₀ is the number of days from J2000.0 (2000-01-01 12:00 UT).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[date, datetime]
|
A date or datetime for which to compute sidereal time. |
required |
longitude
|
float
|
Observer longitude in degrees (−180 to +180). Positive = East. Default 0.0 (Greenwich). |
0.0
|
Returns:
| Type | Description |
|---|---|
float
|
Local sidereal time in hours [0, 24). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date/datetime or longitude is not numeric. |
ValueError
|
If longitude is outside [−180, 180]. |
Usage Example
from datetime import date round(sidereal_time(date(2000, 1, 1), 0.0), 4) 6.6645
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
trimester_of_date(d: Union[datetime, date]) -> int
¶
Return the trimester number for a date.
A trimester is a four-month period. Jan–Apr → 1, May–Aug → 2, Sep–Dec → 3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Trimester number (1–3). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date trimester_of_date(date(2025, 9, 1)) 3
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
week_parity(d: Union[datetime, date]) -> str
¶
Return whether the ISO week number is even or odd.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
Date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date week_parity(date(2025, 1, 6)) 'even'
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
week_year(d: Union[date, datetime]) -> int
¶
Return the ISO week-numbering year for a date.
Description
The ISO week-numbering year can differ from the Gregorian calendar year for dates near the year boundary. For example, 2025-12-29 (Monday) belongs to ISO year 2026 week 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[date, datetime]
|
A |
required |
Returns:
| Type | Description |
|---|---|
int
|
The ISO week-numbering year. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Usage Example
from datetime import date week_year(date(2025, 12, 29)) 2026 week_year(date(2025, 6, 15)) 2025
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
weeks_between_dates(date1: Union[datetime, date], date2: Union[datetime, date]) -> int
¶
Calculate the number of complete weeks between two dates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date1
|
Union[datetime, date]
|
Start date. |
required |
date2
|
Union[datetime, date]
|
End date. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of complete weeks (absolute value). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not date or datetime. |
Example
from datetime import date weeks_between_dates(date(2025, 1, 1), date(2025, 3, 1)) 8
Complexity: O(1)
Source code in shortfx/fxDate/date_evaluations.py
workdays_in_month(year: int, month: int) -> int
¶
Count the number of weekdays (Mon-Fri) in a given month.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Calendar year. |
required |
month
|
int
|
Month (1-12). |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of weekdays. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are not integers. |
ValueError
|
If month is out of range. |
Example
workdays_in_month(2025, 6) 21
Complexity: O(days_in_month)
Source code in shortfx/fxDate/date_evaluations.py
zodiac_sign(d: Union[datetime, date]) -> str
¶
Returns the Western zodiac sign for a date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Union[datetime, date]
|
A date or datetime. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Zodiac sign name in English (e.g. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If d is not a date or datetime. |
Example
from datetime import date zodiac_sign(date(2024, 8, 15)) 'Leo'
Complexity: O(1)