MCPcopy Create free account
hub / github.com/apache/arrow-rs / string_without_timezone_to_timestamp

Function string_without_timezone_to_timestamp

arrow-cast/src/parse.rs:1731–1792  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1729
1730 #[test]
1731 fn string_without_timezone_to_timestamp() {
1732 // string without timezone should always output the same regardless the local or session timezone
1733
1734 let naive_datetime = NaiveDateTime::new(
1735 NaiveDate::from_ymd_opt(2020, 9, 8).unwrap(),
1736 NaiveTime::from_hms_nano_opt(13, 42, 29, 190855000).unwrap(),
1737 );
1738
1739 // Ensure both T and ' ' variants work
1740 assert_eq!(
1741 naive_datetime.and_utc().timestamp_nanos_opt().unwrap(),
1742 parse_timestamp("2020-09-08T13:42:29.190855").unwrap()
1743 );
1744
1745 assert_eq!(
1746 naive_datetime.and_utc().timestamp_nanos_opt().unwrap(),
1747 parse_timestamp("2020-09-08 13:42:29.190855").unwrap()
1748 );
1749
1750 let naive_datetime = NaiveDateTime::new(
1751 NaiveDate::from_ymd_opt(2020, 9, 8).unwrap(),
1752 NaiveTime::from_hms_nano_opt(13, 42, 29, 0).unwrap(),
1753 );
1754
1755 // Ensure both T and ' ' variants work
1756 assert_eq!(
1757 naive_datetime.and_utc().timestamp_nanos_opt().unwrap(),
1758 parse_timestamp("2020-09-08T13:42:29").unwrap()
1759 );
1760
1761 assert_eq!(
1762 naive_datetime.and_utc().timestamp_nanos_opt().unwrap(),
1763 parse_timestamp("2020-09-08 13:42:29").unwrap()
1764 );
1765
1766 let tz: Tz = "+02:00".parse().unwrap();
1767 let date = string_to_datetime(&tz, "2020-09-08 13:42:29").unwrap();
1768 let utc = date.naive_utc().to_string();
1769 assert_eq!(utc, "2020-09-08 11:42:29");
1770 let local = date.naive_local().to_string();
1771 assert_eq!(local, "2020-09-08 13:42:29");
1772
1773 let date = string_to_datetime(&tz, "2020-09-08 13:42:29Z").unwrap();
1774 let utc = date.naive_utc().to_string();
1775 assert_eq!(utc, "2020-09-08 13:42:29");
1776 let local = date.naive_local().to_string();
1777 assert_eq!(local, "2020-09-08 15:42:29");
1778
1779 let dt =
1780 NaiveDateTime::parse_from_str("2020-09-08T13:42:29Z", "%Y-%m-%dT%H:%M:%SZ").unwrap();
1781 let local: Tz = "+08:00".parse().unwrap();
1782
1783 // Parsed as offset from UTC
1784 let date = string_to_datetime(&local, "2020-09-08T13:42:29Z").unwrap();
1785 assert_eq!(dt, date.naive_utc());
1786 assert_ne!(dt, date.naive_local());
1787
1788 // Parsed as offset from local

Callers

nothing calls this directly

Calls 2

string_to_datetimeFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected