none-shall-parse 0.4.8__tar.gz → 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: none-shall-parse
3
- Version: 0.4.8
3
+ Version: 0.6.0
4
4
  Summary: Trinity Shared Python utilities.
5
5
  Author: Andries Niemandt, Jan Badenhorst
6
6
  Author-email: Andries Niemandt <andries.niemandt@trintel.co.za>, Jan Badenhorst <jan@trintel.co.za>
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "none-shall-parse"
7
- version = "0.4.8"
7
+ version = "0.6.0"
8
8
  description = "Trinity Shared Python utilities."
9
9
  readme = "README.md"
10
10
  authors = [
@@ -3,7 +3,7 @@ import logging
3
3
  import time
4
4
  from datetime import date, datetime
5
5
  from typing import Callable, Any, Tuple, Sequence, List
6
- from .types import DateTimeLike
6
+ from .types import DateTimeLike, DateTimeOrDateLike
7
7
 
8
8
  import pendulum
9
9
  from pendulum import DateTime, Date
@@ -417,7 +417,7 @@ def month_span(mso: int) -> Callable[[DateTimeLike], Tuple[DateTime, DateTime]]:
417
417
  return find_dates
418
418
 
419
419
 
420
- def arb_span(dates: Sequence[str | DateTimeLike], naive: bool = False) -> Callable[
420
+ def arb_span(dates: Sequence[str | DateTimeOrDateLike], naive: bool = False) -> Callable[
421
421
  [Any], Tuple[DateTime, DateTime]]:
422
422
  """
423
423
  Parses two given dates and returns a callable function that provides the date range
@@ -452,15 +452,20 @@ def arb_span(dates: Sequence[str | DateTimeLike], naive: bool = False) -> Callab
452
452
 
453
453
  parsed_dates.append(parsed.start_of('day'))
454
454
  else:
455
- # It's already a datetime
456
- if date.tzinfo is None:
457
- # Input is naive, keep it naive using pendulum.naive()
458
- parsed = pendulum.naive(date.year, date.month, date.day,
459
- date.hour, date.minute, date.second,
460
- date.microsecond)
455
+ # It's already a datetime-like object
456
+ if isinstance(date, datetime):
457
+ # datetime objects have tzinfo, hour, minute, etc.
458
+ if date.tzinfo is None:
459
+ # Input is naive, keep it naive using pendulum.naive()
460
+ parsed = pendulum.naive(date.year, date.month, date.day,
461
+ date.hour, date.minute, date.second,
462
+ date.microsecond)
463
+ else:
464
+ # Input is timezone-aware, preserve it
465
+ parsed = pendulum.instance(date)
461
466
  else:
462
- # Input is timezone-aware, preserve it
463
- parsed = pendulum.instance(date)
467
+ # date objects (no time component, no tzinfo) - treat as naive
468
+ parsed = pendulum.naive(date.year, date.month, date.day)
464
469
 
465
470
  parsed_dates.append(parsed.start_of('day'))
466
471
 
@@ -518,13 +523,21 @@ def unroll_span_func(
518
523
  DateUtilsError: If the date range cannot be processed due to invalid dates or formatting.
519
524
  """
520
525
  cover = pendulum.now() if cover is None else cover
521
- naive = cover.tzinfo is None
526
+
522
527
  try:
523
528
  start, end = f(cover)
524
529
  start = pendulum.instance(start)
525
- start = start.naive() if naive else start
526
530
  end = pendulum.instance(end)
527
- end = end.naive() if naive else end
531
+
532
+ # Determine naiveness from the dates returned by f, not from cover
533
+ naive = start.tzinfo is None
534
+ if naive:
535
+ start = start.naive()
536
+ end = end.naive()
537
+
538
+ # Get actual current time for filtering future dates (always "now", not cover)
539
+ current_date_sentinel = pendulum.now().naive() if naive else pendulum.now()
540
+
528
541
  except Exception as e:
529
542
  raise DateUtilsError(f"Function f failed to compute date range: {str(e)}")
530
543
 
@@ -537,9 +550,11 @@ def unroll_span_func(
537
550
  ord_days = []
538
551
  iso_date_strings = []
539
552
  for dt in interval.range(unit="days"):
540
- date_range.append(dt)
541
- ord_days.append(dt.day_of_year)
542
- iso_date_strings.append(dt.format('YYYY-MM-DD'))
553
+ # Filter: only include dates up to today (not future dates)
554
+ if dt <= current_date_sentinel and dt < end:
555
+ date_range.append(dt)
556
+ ord_days.append(dt.day_of_year)
557
+ iso_date_strings.append(dt.format('YYYY-MM-DD'))
543
558
 
544
559
  return date_range, ord_days, iso_date_strings, start, end
545
560