|
25 | 25 | //!
|
26 | 26 | //! let ixdtf_str = "2024-03-02T08:48:00-05:00[America/New_York]";
|
27 | 27 | //!
|
28 |
| -//! let result = IxdtfParser::new(ixdtf_str).parse().unwrap(); |
| 28 | +//! let result = IxdtfParser::from_str(ixdtf_str).parse().unwrap(); |
29 | 29 | //!
|
30 | 30 | //! let date = result.date.unwrap();
|
31 | 31 | //! let time = result.time.unwrap();
|
|
41 | 41 | //! assert_eq!(offset.hour, 5);
|
42 | 42 | //! assert_eq!(offset.minute, 0);
|
43 | 43 | //! assert!(!tz_annotation.critical);
|
44 |
| -//! assert_eq!(tz_annotation.tz, TimeZoneRecord::Name("America/New_York")); |
| 44 | +//! assert_eq!(tz_annotation.tz, TimeZoneRecord::Name("America/New_York".as_bytes())); |
45 | 45 | //! ```
|
46 | 46 | //!
|
47 | 47 | //! ## Date/Time Strings
|
|
142 | 142 | //! let example_one =
|
143 | 143 | //! "2024-03-02T08:48:00-05:00[u-ca=iso8601][America/New_York]";
|
144 | 144 | //!
|
145 |
| -//! let mut ixdtf = IxdtfParser::new(example_one); |
146 |
| -//! |
147 |
| -//! let result = ixdtf.parse(); |
| 145 | +//! let result = IxdtfParser::from_str(example_one).parse(); |
148 | 146 | //!
|
149 | 147 | //! assert_eq!(result, Err(ParserError::AnnotationKeyLeadingChar));
|
150 | 148 | //! ```
|
|
158 | 156 | //! ```rust
|
159 | 157 | //! use ixdtf::{parsers::IxdtfParser, ParserError};
|
160 | 158 | //!
|
161 |
| -//! let example_one = "2024-03-02T08:48:00-05:00[u-ca=iso8601][!u-ca=japanese]"; |
| 159 | +//! let example_two = "2024-03-02T08:48:00-05:00[u-ca=iso8601][!u-ca=japanese]"; |
162 | 160 | //!
|
163 |
| -//! let result = IxdtfParser::new(example_one).parse(); |
| 161 | +//! let result = IxdtfParser::from_str(example_two).parse(); |
164 | 162 | //!
|
165 | 163 | //! assert_eq!(result, Err(ParserError::CriticalDuplicateCalendar));
|
166 | 164 | //! ```
|
|
173 | 171 | //! ```rust
|
174 | 172 | //! use ixdtf::{parsers::IxdtfParser, ParserError};
|
175 | 173 | //!
|
176 |
| -//! let example_one = |
| 174 | +//! let example_three = |
177 | 175 | //! "2024-03-02T08:48:00-05:00[u-ca=iso8601][!answer-to-universe=fortytwo]";
|
178 | 176 | //!
|
179 |
| -//! let result = IxdtfParser::new(example_one).parse(); |
| 177 | +//! let result = IxdtfParser::from_str(example_three).parse(); |
180 | 178 | //!
|
181 | 179 | //! assert_eq!(result, Err(ParserError::UnrecognizedCritical));
|
182 | 180 | //! ```
|
|
207 | 205 | //! ```rust
|
208 | 206 | //! use ixdtf::parsers::{IxdtfParser, records::TimeZoneRecord};
|
209 | 207 | //!
|
210 |
| -//! let example_one = "2024-03-02T08:48:00+01:00[!America/New_York]"; |
211 |
| -//! |
212 |
| -//! let mut ixdtf = IxdtfParser::new(example_one); |
| 208 | +//! let example_two = "2024-03-02T08:48:00+01:00[!America/New_York]"; |
213 | 209 | //!
|
214 |
| -//! let result = ixdtf.parse().unwrap(); |
| 210 | +//! let result = IxdtfParser::from_str(example_two).parse().unwrap(); |
215 | 211 | //!
|
216 | 212 | //! let tz_annotation = result.tz.unwrap();
|
217 | 213 | //! let offset = result.offset.unwrap();
|
218 | 214 | //!
|
219 | 215 | //! // The time zone annotation and offset conflict with each other, and must therefore be
|
220 | 216 | //! // resolved by the user.
|
221 | 217 | //! assert!(tz_annotation.critical);
|
222 |
| -//! assert_eq!(tz_annotation.tz, TimeZoneRecord::Name("America/New_York")); |
| 218 | +//! assert_eq!(tz_annotation.tz, TimeZoneRecord::Name("America/New_York".as_bytes())); |
223 | 219 | //! assert_eq!(offset.hour, 1);
|
224 | 220 | //! ```
|
225 | 221 | //!
|
|
254 | 250 | //!
|
255 | 251 | //! let mut answer = None;
|
256 | 252 | //!
|
257 |
| -//! let _ = IxdtfParser::new(example_with_custom_key).parse_with_annotation_handler(|annotation| { |
258 |
| -//! if annotation.key == "answer-to-universe" { |
| 253 | +//! let _ = IxdtfParser::from_str(example_with_custom_key).parse_with_annotation_handler(|annotation| { |
| 254 | +//! if annotation.key == "answer-to-universe".as_bytes() { |
259 | 255 | //! answer.get_or_insert(annotation);
|
260 | 256 | //! // Found our value! We don't need `ixdtf` to handle this annotation.
|
261 | 257 | //! return None
|
|
268 | 264 | //! let answer = answer.unwrap();
|
269 | 265 | //!
|
270 | 266 | //! assert!(answer.critical);
|
271 |
| -//! assert_eq!(answer.value, "fortytwo"); |
| 267 | +//! assert_eq!(answer.value, "fortytwo".as_bytes()); |
272 | 268 | //! ```
|
273 | 269 | //!
|
274 | 270 | //! It is worth noting that in the above example the annotation above found is a critically flagged
|
|
0 commit comments