solr_date() parses a scalar input into an internal S7 SolrDate object. The resulting object can represent a single instant, a Date Math expression, an unbounded boundary (*), or a Solr range.

solr_date(x)

Arguments

x

A scalar input to parse. Supported inputs are:

  • an existing SolrDate object, which is returned unchanged;

  • a scalar Date or POSIXt object;

  • a scalar numeric value, which is first converted to character;

  • a scalar character string representing either a single boundary or a complete Solr range expression.

POSIXt inputs must use the "UTC" timezone.

Value

An internal S7 object inheriting from SolrDate. The exact subclass is an implementation detail and may represent a single instant, a Date Math expression, an unbounded boundary, or a range.

Details

Character inputs support the following forms:

  • Simplified dates such as "2025", "2025-02", "2025-02-03", and "20250203".

  • Datetimes accepted by the internal parser, including ISO-like forms such as "2025-01-15T12:30:45Z", timezone offsets like "+08:00", and common separators such as "/" and ".".

  • Solr Date Math expressions rooted at NOW, e.g. "NOW", "NOW-1YEAR", or "NOW/DAY-1YEAR+6MONTHS".

  • Fixed-base Date Math expressions of the form "<datetime>Z<math>", e.g. "2025-01-01T00:00:00Z+1MONTH".

  • Solr range expressions using the exact separator " TO " and boundary brackets \[\] or \{\}, e.g. "\[2000 TO 2010\]", "\{2000 TO 2010\]", or "\[* TO *\]".

Supported Date Math operators are +, -, and /. Supported units are YEAR, YEARS, MONTH, MONTHS, DAY, DAYS, DATE, HOUR, HOURS, MINUTE, MINUTES, SECOND, SECONDS, MILLI, MILLIS, MILLISECOND, and MILLISECONDS.

Use format() or as.character() to render a parsed value. format() supports as = "iso" and as = "num". as.POSIXct() can be used on instants; for ranges it returns the start boundary with a warning, and for unbounded or Date Math values it errors because no single concrete instant is available.

See also

Examples

solr_date("2025")
#> <SolrDate>
#> - "2025-01-01T00:00:00Z"
solr_date("2025-02")
#> <SolrDate>
#> - "2025-02-01T00:00:00Z"
solr_date("20250203")
#> <SolrDate>
#> - "2025-02-03T00:00:00Z"
solr_date("2025-01-15T12:30:45Z")
#> <SolrDate>
#> - "2025-01-15T12:30:45Z"

solr_date("NOW")
#> <SolrDate>
#> - "NOW"
solr_date("NOW/DAY-1YEAR+6MONTHS")
#> <SolrDate>
#> - "NOW/DAY-1YEAR+6MONTHS"
solr_date("2025-01-01T00:00:00Z+1MONTH")
#> <SolrDate>
#> - "2025-01-01T00:00:00Z+1MONTH"

solr_date("[2000 TO 2010]")
#> <SolrDate>
#> - "[2000-01-01T00:00:00Z TO 2010-01-01T00:00:00Z]"
solr_date("{2000 TO 2010]")
#> <SolrDate>
#> - "{2000-01-01T00:00:00Z TO 2010-01-01T00:00:00Z]"
solr_date("[* TO *]")
#> <SolrDate>
#> - "[* TO *]"

x <- solr_date("2025-01-15T12:30:45Z")
format(x)
#> [1] "2025-01-15T12:30:45Z"
format(x, as = "num")
#> Warning: Loss of time information when rendering in 'num' format for SolrDate '2025-01-15 12:30:45'.
#> [1] "20250115"
as.character(x)
#> [1] "2025-01-15T12:30:45Z"
as.POSIXct(x)
#> [1] "2025-01-15 12:30:45 UTC"
is.solr_date(x)
#> [1] TRUE
print(x)
#> <SolrDate>
#> - "2025-01-15T12:30:45Z"