Skip to content

Conversation

@wtn
Copy link
Contributor

@wtn wtn commented Dec 4, 2025

Addresses #21.

Adds optional chrono feature flag that enables conversions from chrono date and datetime types to DateRange and DateTimeRange.

Changes

  • Added chrono as an optional dependency (>=0.4.34, minimal features: alloc only)
  • Implemented From traits for DateTimeRange:
    • Range<DateTime<Tz>> and RangeInclusive<DateTime<Tz>> (generic over timezone)
    • (DateTime<Tz>, DateTime<Tz>) tuple
    • (DateTime<Tz>, chrono::Duration) tuple
    • NaiveDate, Range<NaiveDate>, RangeInclusive<NaiveDate>, (NaiveDate, NaiveDate)
  • Implemented From traits for DateRange:
    • NaiveDate, Range<NaiveDate>, RangeInclusive<NaiveDate>, (NaiveDate, NaiveDate)

Usage

[dependencies]
databento = { version = "0.37", features = ["chrono"] }
use chrono::{TimeZone, Utc};
use databento::historical::DateTimeRange;

let start = Utc.with_ymd_and_hms(2024, 3, 15, 9, 30, 0).unwrap();
let end = Utc.with_ymd_and_hms(2024, 3, 15, 16, 0, 0).unwrap();
let range = DateTimeRange::from(start..end);

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this change been tested?

  • cargo test --features chrono chrono_tests - 14 new tests for chrono conversions
  • ./scripts/test.sh - all 50 tests pass (includes chrono tests)
  • cargo test (without chrono feature) - 36 existing tests still pass

Checklist

  • My code builds locally with no new warnings (scripts/build.sh)
  • My code follows the style guidelines (scripts/lint.sh and scripts/format.sh)
  • New and existing unit tests pass locally with my changes (scripts/test.sh)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Declaration

I confirm this contribution is made under an Apache 2.0 license and that I have the authority
necessary to make this contribution on behalf of its copyright owner.

@wtn
Copy link
Contributor Author

wtn commented Dec 4, 2025

@TheDan64 Is this feature still relevant for you?

@threecgreen
Copy link
Collaborator

Hi @wtn,
Thanks for opening the PR with tests!

In order to merge this, I'd want the chrono support to extend to Live with Subscription::start. You could probably repurpose the DateTimeLike trait that's currently in reference.rs for this purpose.

@wtn wtn force-pushed the chrono branch 2 times, most recently from 4e3d295 to e6c2400 Compare December 4, 2025 20:24
@wtn wtn marked this pull request as ready for review December 4, 2025 20:29
@wtn
Copy link
Contributor Author

wtn commented Dec 4, 2025

Thanks, addressed feedback and fixed the rustfmt error.

@threecgreen
Copy link
Collaborator

Committed in 6eb1d48. Thanks again!

@threecgreen threecgreen closed this Dec 5, 2025
@threecgreen threecgreen mentioned this pull request Dec 5, 2025
@wtn wtn deleted the chrono branch December 13, 2025 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants