MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_timestamp_string

Function parse_timestamp_string

src/repr/src/strconv.rs:376–406  ·  view source on GitHub ↗

Use the following grammar to parse `s` into: - `NaiveDate` - `NaiveTime` - Timezone string `NaiveDate` and `NaiveTime` are appropriate to compute a `NaiveDateTime`, which can be used in conjunction with a timezone string to generate a `DateTime `. ```text ::= [ ] ::= <m

(s: &str)

Source from the content-addressed store, hash-verified

374/// <sign> <hours value> <colon> <minutes value>
375/// ```
376fn parse_timestamp_string(s: &str) -> Result<(NaiveDate, NaiveTime, Timezone), String> {
377 if s.is_empty() {
378 return Err("timestamp string is empty".into());
379 }
380
381 // PostgreSQL special date-time inputs
382 // https://www.postgresql.org/docs/12/datatype-datetime.html#id-1.5.7.13.18.8
383 // We should add support for other values here, e.g. infinity
384 // which @quodlibetor is willing to add to the chrono package.
385 if s == "epoch" {
386 return Ok((
387 NaiveDate::from_ymd_opt(1970, 1, 1).unwrap(),
388 NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
389 Default::default(),
390 ));
391 }
392
393 let (ts_string, tz_string, era) = datetime::split_timestamp_string(s);
394
395 let pdt = ParsedDateTime::build_parsed_datetime_timestamp(ts_string, era)?;
396 let d: NaiveDate = pdt.compute_date()?;
397 let t: NaiveTime = pdt.compute_time()?;
398
399 let offset = if tz_string.is_empty() {
400 Default::default()
401 } else {
402 Timezone::parse(tz_string, TimezoneSpec::Iso)?
403 };
404
405 Ok((d, t, offset))
406}
407
408/// Parses a [`Date`] from `s`.
409pub fn parse_date(s: &str) -> Result<Date, ParseError> {

Callers 3

parse_dateFunction · 0.85
parse_timestampFunction · 0.85
parse_timestamptzFunction · 0.85

Calls 6

split_timestamp_stringFunction · 0.85
unwrapMethod · 0.80
compute_dateMethod · 0.80
compute_timeMethod · 0.80
parseFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected