@@ -533,8 +533,8 @@ impl<'m, 'v> Variant<'m, 'v> {
533533
534534 /// Converts this variant to a `DateTime<Utc>` if possible.
535535 ///
536- /// Returns `Some(DateTime<Utc>)` for timestamp variants,
537- /// `None` for non-timestamp variants.
536+ /// Returns `Some(DateTime<Utc>)` for [`Variant::TimestampMicros`] variants,
537+ /// `None` for other variants.
538538 ///
539539 /// # Examples
540540 ///
@@ -545,92 +545,81 @@ impl<'m, 'v> Variant<'m, 'v> {
545545 /// // you can extract a DateTime<Utc> from a UTC-adjusted variant
546546 /// let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt(12, 34, 56, 780).unwrap().and_utc();
547547 /// let v1 = Variant::from(datetime);
548- /// assert_eq!(v1.as_datetime_utc(), Some(datetime));
548+ /// assert_eq!(v1.as_timestamp_micros(), Some(datetime));
549+ ///
550+ /// // but not for other variants.
549551 /// let datetime_nanos = NaiveDate::from_ymd_opt(2025, 8, 14).unwrap().and_hms_nano_opt(12, 33, 54, 123456789).unwrap().and_utc();
550552 /// let v2 = Variant::from(datetime_nanos);
551- /// assert_eq!(v2.as_datetime_utc(), Some(datetime_nanos));
552- ///
553- /// // but not from other variants
554- /// let v3 = Variant::from("hello!");
555- /// assert_eq!(v3.as_datetime_utc(), None);
553+ /// assert_eq!(v2.as_timestamp_micros(), None);
556554 /// ```
557- pub fn as_datetime_utc ( & self ) -> Option < DateTime < Utc > > {
555+ pub fn as_timestamp_micros ( & self ) -> Option < DateTime < Utc > > {
558556 match * self {
559- Variant :: TimestampMicros ( d) | Variant :: TimestampNanos ( d ) => Some ( d) ,
557+ Variant :: TimestampMicros ( d) => Some ( d) ,
560558 _ => None ,
561559 }
562560 }
563561
564- /// Converts this variant to a `i64` representing microseconds since the Unix epoch if possible.
565- /// This is useful when convert the variant to arrow types.
562+ /// Converts this variant to a `NaiveDateTime` if possible.
566563 ///
567- /// Returns Some(i64) for [`Variant::TimestampMicros`] and [`Variant::TimestampNtzMicros`],
568- /// None for the other variant types.
564+ /// Returns `Some(NaiveDateTime)` for [`Variant::TimestampNtzMicros`] variants,
565+ /// `None` for other variants.
566+ ///
567+ /// # Examples
569568 ///
570569 /// ```
571570 /// use parquet_variant::Variant;
572571 /// use chrono::NaiveDate;
573572 ///
574- /// // you can extract an i64 from Variant::TimestampMicros
575- /// let datetime = NaiveDate::from_ymd_opt(2025, 10, 03 ).unwrap().and_hms_milli_opt(12, 34, 56, 789 ).unwrap().and_utc ();
573+ /// // you can extract a NaiveDateTime from a non-UTC-adjusted variant
574+ /// let datetime = NaiveDate::from_ymd_opt(2025, 4, 16 ).unwrap().and_hms_milli_opt(12, 34, 56, 780 ).unwrap();
576575 /// let v1 = Variant::from(datetime);
577- /// assert_eq!(v1.as_timestamp_micros (), Some(1759494896789000 ));
576+ /// assert_eq!(v1.as_timestamp_ntz_micros (), Some(datetime ));
578577 ///
579- /// // or Variant::TimestampNtzMicros
580- /// let datetime_ntz = NaiveDate::from_ymd_opt(2025, 10, 03).unwrap().and_hms_milli_opt(12, 34, 56, 789).unwrap();
581- /// let v2 = Variant::from(datetime_ntz);
582- /// assert_eq!(v1.as_timestamp_micros(), Some(1759494896789000));
583- ///
584- /// // but not from other variants
585- /// let datetime_nanos = NaiveDate::from_ymd_opt(2025, 10, 03).unwrap().and_hms_nano_opt(12, 34, 56, 789123456).unwrap().and_utc();
586- /// let v3 = Variant::from(datetime_nanos);
587- /// assert_eq!(v3.as_timestamp_micros(), None);
578+ /// // but not for other variants.
579+ /// let datetime_nanos = NaiveDate::from_ymd_opt(2025, 8, 14).unwrap().and_hms_nano_opt(12, 33, 54, 123456789).unwrap();
580+ /// let v2 = Variant::from(datetime_nanos);
581+ /// assert_eq!(v2.as_timestamp_micros(), None);
588582 /// ```
589- pub fn as_timestamp_micros ( & self ) -> Option < i64 > {
583+ pub fn as_timestamp_ntz_micros ( & self ) -> Option < NaiveDateTime > {
590584 match * self {
591- Variant :: TimestampMicros ( d) => Some ( d. timestamp_micros ( ) ) ,
592- Variant :: TimestampNtzMicros ( d) => Some ( d. and_utc ( ) . timestamp_micros ( ) ) ,
585+ Variant :: TimestampNtzMicros ( d) => Some ( d) ,
593586 _ => None ,
594587 }
595588 }
596589
597- /// Converts this variant to a `i64` representing nanoseconds since the Unix epoch if possible.
598- /// This is useful when convert the variant to arrow types.
590+ /// Converts this variant to a `DateTime<Utc>` if possible.
591+ ///
592+ /// Returns `Some(DateTime<Utc>)` for [`Variant::TimestampNanos`] variants,
593+ /// `None` for other variants.
599594 ///
600- /// Returns Some(i64) for [`Variant::TimestampNanos`] and [`Variant::TimestampNtzNanos`],
601- /// None for the other variant types.
595+ /// # Examples
602596 ///
603597 /// ```
604598 /// use parquet_variant::Variant;
605599 /// use chrono::NaiveDate;
606600 ///
607- /// // you can extract an i64 from Variant::TimestampNanos
608- /// let datetime = NaiveDate::from_ymd_opt(2025, 10, 03 ).unwrap().and_hms_nano_opt(12, 34, 56, 789123456).unwrap().and_utc();
601+ /// // you can extract a DateTime<Utc> from a UTC-adjusted variant
602+ /// let datetime = NaiveDate::from_ymd_opt(2025, 4, 16 ).unwrap().and_hms_nano_opt(12, 34, 56, 789123456).unwrap().and_utc();
609603 /// let v1 = Variant::from(datetime);
610- /// assert_eq!(v1.as_timestamp_nanos(), Some(1759494896789123456));
611- ///
612- /// // or Variant::TimestampNtzNanos
613- /// let datetime_ntz = NaiveDate::from_ymd_opt(2025, 10, 03).unwrap().and_hms_nano_opt(12, 34, 56, 789123456).unwrap();
614- /// let v2 = Variant::from(datetime_ntz);
615- /// assert_eq!(v1.as_timestamp_nanos(), Some(1759494896789123456));
604+ /// assert_eq!(v1.as_timestamp_nanos(), Some(datetime));
616605 ///
617- /// // but not from other variants
618- /// let datetime_micros = NaiveDate::from_ymd_opt(2025, 10, 03).unwrap().and_hms_micro_opt(12, 34, 56, 789).unwrap().and_utc();
619- /// let v3 = Variant::from(datetime_micros);
620- /// assert_eq!(v3.as_timestamp_nanos(), None);
606+ /// // but not for other variants.
607+ /// let datetime_micros = NaiveDate::from_ymd_opt(2025, 8, 14).unwrap().and_hms_milli_opt(12, 33, 54, 123).unwrap().and_utc();
608+ /// // this will convert to `Variant::TimestampMicros`.
609+ /// let v2 = Variant::from(datetime_micros);
610+ /// assert_eq!(v2.as_timestamp_nanos(), None);
621611 /// ```
622- pub fn as_timestamp_nanos ( & self ) -> Option < i64 > {
612+ pub fn as_timestamp_nanos ( & self ) -> Option < DateTime < Utc > > {
623613 match * self {
624- Variant :: TimestampNanos ( d) => d. timestamp_nanos_opt ( ) ,
625- Variant :: TimestampNtzNanos ( d) => d. and_utc ( ) . timestamp_nanos_opt ( ) ,
614+ Variant :: TimestampNanos ( d) => Some ( d) ,
626615 _ => None ,
627616 }
628617 }
629618
630619 /// Converts this variant to a `NaiveDateTime` if possible.
631620 ///
632- /// Returns `Some(NaiveDateTime)` for timestamp variants,
633- /// `None` for non-timestamp variants.
621+ /// Returns `Some(NaiveDateTime)` for [`Variant::TimestampNtzNanos`] variants,
622+ /// `None` for other variants.
634623 ///
635624 /// # Examples
636625 ///
@@ -639,22 +628,19 @@ impl<'m, 'v> Variant<'m, 'v> {
639628 /// use chrono::NaiveDate;
640629 ///
641630 /// // you can extract a NaiveDateTime from a non-UTC-adjusted variant
642- /// let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt (12, 34, 56, 780 ).unwrap();
631+ /// let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_nano_opt (12, 34, 56, 789123456 ).unwrap();
643632 /// let v1 = Variant::from(datetime);
644- /// assert_eq!(v1.as_naive_datetime(), Some(datetime));
645- ///
646- /// // or a UTC-adjusted variant
647- /// let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_nano_opt(12, 34, 56, 123456789).unwrap();
648- /// let v2 = Variant::from(datetime);
649- /// assert_eq!(v2.as_naive_datetime(), Some(datetime));
633+ /// assert_eq!(v1.as_timestamp_ntz_nanos(), Some(datetime));
650634 ///
651- /// // but not from other variants
652- /// let v3 = Variant::from("hello!");
653- /// assert_eq!(v3.as_naive_datetime(), None);
635+ /// // but not for other variants.
636+ /// let datetime_micros = NaiveDate::from_ymd_opt(2025, 8, 14).unwrap().and_hms_milli_opt(12, 33, 54, 123).unwrap();
637+ /// // this will convert to `Variant::TimestampMicros`.
638+ /// let v2 = Variant::from(datetime_micros);
639+ /// assert_eq!(v2.as_timestamp_ntz_nanos(), None);
654640 /// ```
655- pub fn as_naive_datetime ( & self ) -> Option < NaiveDateTime > {
641+ pub fn as_timestamp_ntz_nanos ( & self ) -> Option < NaiveDateTime > {
656642 match * self {
657- Variant :: TimestampNtzMicros ( d ) | Variant :: TimestampNtzNanos ( d) => Some ( d) ,
643+ Variant :: TimestampNtzNanos ( d) => Some ( d) ,
658644 _ => None ,
659645 }
660646 }
0 commit comments