Package edu.caltech.nanodb.expressions
Class DateTimeUtils
- java.lang.Object
-
- edu.caltech.nanodb.expressions.DateTimeUtils
-
public class DateTimeUtils extends java.lang.Object
Provides a number of utility operations for working with dates, times and timestamps.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.time.format.DateTimeFormatter[]
DATE_FORMATS
An array of date format specifications that NanoDB recognizes.private static java.time.format.DateTimeFormatter[]
DATETIME_FORMATS
An array of date/time format specifications that NanoDB recognizes.private static java.time.format.DateTimeFormatter[]
TIME_FORMATS
An array of time format specifications that NanoDB recognizes.
-
Constructor Summary
Constructors Constructor Description DateTimeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.time.LocalDate
parseDate(java.lang.String s)
Attempts to parse a string into a date value using the formats specified inDATE_FORMATS
.static java.time.LocalDateTime
parseDateTime(java.lang.String s)
Attempts to parse a string into a date/time value using the formats specified inDATETIME_FORMATS
.static java.time.temporal.TemporalAmount
parseInterval(java.lang.String s)
Attempts to parse a string into some kind of "temporal amount" or INTERVAL value.static java.time.temporal.Temporal
parseTemporal(java.lang.String s)
Attempts to parse a string into some kind of temporal value using the formats specified inDATETIME_FORMATS
,DATE_FORMATS
, andTIME_FORMATS
.static java.time.LocalTime
parseTime(java.lang.String s)
Attempts to parse a string into a time value using the formats specified inTIME_FORMATS
.
-
-
-
Field Detail
-
DATE_FORMATS
private static final java.time.format.DateTimeFormatter[] DATE_FORMATS
An array of date format specifications that NanoDB recognizes. New formats can be added to this array to expand what NanoDB is able to parse.
-
TIME_FORMATS
private static final java.time.format.DateTimeFormatter[] TIME_FORMATS
An array of time format specifications that NanoDB recognizes. New formats can be added to this array to expand what NanoDB is able to parse.
-
DATETIME_FORMATS
private static final java.time.format.DateTimeFormatter[] DATETIME_FORMATS
An array of date/time format specifications that NanoDB recognizes. New formats can be added to this array to expand what NanoDB is able to parse.
-
-
Method Detail
-
parseDateTime
public static java.time.LocalDateTime parseDateTime(java.lang.String s)
Attempts to parse a string into a date/time value using the formats specified inDATETIME_FORMATS
.- Parameters:
s
- the string to attempt to parse into a date/time- Returns:
- an object holding the date/time value
- Throws:
java.time.format.DateTimeParseException
- if the string couldn't be parsed into a date/time value.
-
parseDate
public static java.time.LocalDate parseDate(java.lang.String s)
Attempts to parse a string into a date value using the formats specified inDATE_FORMATS
.- Parameters:
s
- the string to attempt to parse into a date- Returns:
- an object holding the date value
- Throws:
java.time.format.DateTimeParseException
- if the string couldn't be parsed into a date value.
-
parseTime
public static java.time.LocalTime parseTime(java.lang.String s)
Attempts to parse a string into a time value using the formats specified inTIME_FORMATS
.- Parameters:
s
- the string to attempt to parse into a time- Returns:
- an object holding the time value
- Throws:
java.time.format.DateTimeParseException
- if the string couldn't be parsed into a time value.
-
parseTemporal
public static java.time.temporal.Temporal parseTemporal(java.lang.String s)
Attempts to parse a string into some kind of temporal value using the formats specified inDATETIME_FORMATS
,DATE_FORMATS
, andTIME_FORMATS
. Attempts are made in this order, so a date/time will be produced if possible, then a date, and finally a time.- Parameters:
s
- the string to attempt to parse into a temporal value- Returns:
- an object holding the temporal value
- Throws:
java.time.format.DateTimeParseException
- if the string couldn't be parsed into a temporal value.
-
parseInterval
public static java.time.temporal.TemporalAmount parseInterval(java.lang.String s)
Attempts to parse a string into some kind of "temporal amount" or INTERVAL value. Only one interval format is supported at this time: "N [YEAR|MONTH|WEEK|DAY|HOUR|MINUTE|SECOND]S?", where N is an integer. The units may be singular or plural; e.g. both "YEAR" and "YEARS" is supported.- Parameters:
s
- the string to attempt to parse into a temporal amount- Returns:
- an object holding the temporal amount
- Throws:
java.time.format.DateTimeParseException
- if the string couldn't be parsed into a temporal amount.
-
-