neutralts/bif/
parse_bif_date.rs1#![doc = include_str!("../../doc/bif-date.md")]
2
3use crate::{bif::constants::*, bif::Bif, bif::BifError, constants::*};
4use chrono::Utc;
5
6impl<'a> Bif<'a> {
7 pub(crate) fn parse_bif_date(&mut self) -> Result<(), BifError> {
12 if self.mod_filter || self.mod_negate || self.mod_scope {
13 return Err(self.bif_error(BIF_ERROR_MODIFIER_NOT_ALLOWED));
14 }
15
16 self.extract_params_code(true);
17
18 if !self.flags.is_empty() {
19 return Err(self.bif_error(BIF_ERROR_FLAGS_NOT_ALLOWED));
20 }
21
22 let now = Utc::now();
23
24 if self.src.contains(BIF_OPEN) {
25 self.code = new_child_parse!(self, &self.code, self.mod_scope);
26 } else {
27 self.code = self.src.trim().to_string();
28 }
29
30 if self.code.is_empty() {
31 self.out = now.timestamp().to_string();
32 } else {
33 self.out = now.format(&self.src).to_string();
34 }
35
36 Ok(())
37 }
38}
39
40#[cfg(test)]
41#[path = "parse_bif_date_tests.rs"]
42mod tests;