-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathmod.rs
More file actions
64 lines (55 loc) · 2.39 KB
/
mod.rs
File metadata and controls
64 lines (55 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! The builtins module contains the main implementation of the Temporal builtins
#[cfg(feature = "compiled_data")]
pub mod compiled;
pub mod core;
pub use core::*;
#[cfg(feature = "compiled_data")]
use std::sync::LazyLock;
#[cfg(feature = "compiled_data")]
use timezone_provider::tzif::CompiledTzdbProvider;
#[cfg(all(test, feature = "compiled_data"))]
use timezone_provider::tzif::FsTzdbProvider;
#[cfg(feature = "compiled_data")]
pub static TZ_PROVIDER: LazyLock<CompiledTzdbProvider> =
LazyLock::new(CompiledTzdbProvider::default);
#[cfg(all(test, feature = "compiled_data"))]
pub(crate) static FS_TZ_PROVIDER: LazyLock<FsTzdbProvider> = LazyLock::new(FsTzdbProvider::default);
#[cfg(test)]
mod tests {
use super::{Instant, PlainDate, PlainDateTime};
#[test]
fn builtins_from_str_10_digit_fractions() {
// Failure case with 10 digits
let test = "2020-01-01T00:00:00.1234567890Z";
let result = Instant::from_utf8(test.as_bytes());
assert!(result.is_err(), "Instant fraction should be invalid");
let result = PlainDate::from_utf8(test.as_bytes());
assert!(result.is_err(), "PlainDate fraction should be invalid");
let result = PlainDateTime::from_utf8(test.as_bytes());
assert!(result.is_err(), "PlainDateTime fraction should be invalid");
}
#[test]
fn instant_based_10_digit_offset() {
let test = "2020-01-01T00:00:00.123456789+02:30:00.1234567890[UTC]";
let result = Instant::from_utf8(test.as_bytes());
assert!(result.is_err(), "Instant should be invalid");
}
#[test]
fn instant_based_9_digit_offset() {
let test = "2020-01-01T00:00:00.123456789+02:30:00.123456789[UTC]";
let result = Instant::from_utf8(test.as_bytes());
assert!(result.is_ok(), "Instant should be valid");
}
#[test]
fn builtin_from_str_9_digit_fractions() {
// Success case with 9 digits
let test = "2020-01-01T00:00:00.123456789Z";
let result = Instant::from_utf8(test.as_bytes());
assert!(result.is_ok(), "Instant fraction should be valid");
let test = "2020-01-01T00:00:00.123456789";
let result = PlainDate::from_utf8(test.as_bytes());
assert!(result.is_ok(), "PlainDate fraction should be valid");
let result = PlainDateTime::from_utf8(test.as_bytes());
assert!(result.is_ok(), "PlainDateTime fraction should be valid");
}
}