(&self, meta: &ParseNestedMeta)
| 309 | |
| 310 | impl Time { |
| 311 | pub fn assert(&self, meta: &ParseNestedMeta) -> Result<(), syn::Error> { |
| 312 | if matches!(self.target, Some(ValueOrPath::Value(_))) && self.format.is_none() { |
| 313 | return Err(meta.error("string literal targets must contain a format")); |
| 314 | } |
| 315 | |
| 316 | if matches!(self.target, Some(ValueOrPath::Path(_))) && self.format.is_some() { |
| 317 | return Err(meta.error("path targets cannot contain formats")); |
| 318 | } |
| 319 | |
| 320 | let no_multiplier = matches!(self.target, Some(ValueOrPath::Path(_))) |
| 321 | && matches!(self.multiplier, TimeMultiplier::None); |
| 322 | |
| 323 | if let (Some(ValueOrPath::Value(date_str)), Some(format)) = (&self.target, &self.format) { |
| 324 | let dt = NaiveDateTime::parse_from_str(date_str, format); |
| 325 | let d = NaiveDate::parse_from_str(date_str, format); |
| 326 | if dt.is_err() && d.is_err() { |
| 327 | abort!( |
| 328 | meta.path.span(), |
| 329 | "The target string does not match the provided format" |
| 330 | ) |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | match self.op { |
| 335 | TimeOp::BeforeNow => { |
| 336 | if self.duration.is_some() { |
| 337 | abort!(meta.path.span(), "before_now cannot have interval"); |
| 338 | } |
| 339 | if self.target.is_some() { |
| 340 | abort!(meta.path.span(), "before_now cannot have target"); |
| 341 | } |
| 342 | } |
| 343 | TimeOp::AfterNow => { |
| 344 | if self.duration.is_some() { |
| 345 | abort!(meta.path.span(), "after_now cannot have interval"); |
| 346 | } |
| 347 | if self.target.is_some() { |
| 348 | abort!(meta.path.span(), "after_now cannot have target"); |
| 349 | } |
| 350 | } |
| 351 | TimeOp::Before => { |
| 352 | if self.target.is_none() { |
| 353 | abort!(meta.path.span(), "before must have a target"); |
| 354 | } |
| 355 | if self.duration.is_some() { |
| 356 | abort!(meta.path.span(), "before cannot have interval"); |
| 357 | } |
| 358 | } |
| 359 | TimeOp::After => { |
| 360 | if self.target.is_none() { |
| 361 | abort!(meta.path.span(), "after must have target"); |
| 362 | } |
| 363 | if self.duration.is_some() { |
| 364 | abort!(meta.path.span(), "after cannot have interval"); |
| 365 | } |
| 366 | } |
| 367 | TimeOp::BeforeFromNow => { |
| 368 | if no_multiplier { |
no test coverage detected