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

Function parse_fixed_offset

arrow-array/src/timezone.rs:25–49  ·  view source on GitHub ↗

Parses a fixed offset of the form "+09:00", "-09" or "+0930"

(tz: &str)

Source from the content-addressed store, hash-verified

23
24/// Parses a fixed offset of the form "+09:00", "-09" or "+0930"
25fn parse_fixed_offset(tz: &str) -> Option<FixedOffset> {
26 let bytes = tz.as_bytes();
27
28 let mut values = match bytes.len() {
29 // [+-]XX:XX
30 6 if bytes[3] == b':' => [bytes[1], bytes[2], bytes[4], bytes[5]],
31 // [+-]XXXX
32 5 => [bytes[1], bytes[2], bytes[3], bytes[4]],
33 // [+-]XX
34 3 => [bytes[1], bytes[2], b'0', b'0'],
35 _ => return None,
36 };
37 values.iter_mut().for_each(|x| *x = x.wrapping_sub(b'0'));
38 if values.iter().any(|x| *x > 9) {
39 return None;
40 }
41 let secs =
42 (values[0] * 10 + values[1]) as i32 * 60 * 60 + (values[2] * 10 + values[3]) as i32 * 60;
43
44 match bytes[0] {
45 b'+' => FixedOffset::east_opt(secs),
46 b'-' => FixedOffset::west_opt(secs),
47 _ => None,
48 }
49}
50
51#[cfg(feature = "chrono-tz")]
52mod private {

Callers 1

from_strMethod · 0.85

Calls 4

as_bytesMethod · 0.45
lenMethod · 0.45
wrapping_subMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected