public class ScriptCalendar2
extends java.lang.Object
The underlying Calendar2 class is Copyright (c) 2005 Robert Simons (CoHortSoftware@gmail.com). See the MIT/X-like license in com/cohort/util/LICENSE.txt.
Modifier and Type | Field and Description |
---|---|
static int |
AM_PM |
static int |
BC |
static int |
DATE
1..
|
static int |
DAY_OF_YEAR |
static int |
DST_OFFSET
in millis
|
static int |
ERA
These are the fields in a Calendar or GregorianCalendar object.
|
static int |
HOUR
0..11, so rarely used
|
static int |
HOUR_OF_DAY
0..23
|
static int |
MILLISECOND |
static int |
MINUTE |
static int |
MONTH
Jan=0, ...
|
static int |
SECOND |
static int |
YEAR |
static int |
ZONE_OFFSET
in millis
|
Constructor and Description |
---|
ScriptCalendar2() |
Modifier and Type | Method and Description |
---|---|
static double |
clearSmallerFields(double epochSeconds,
int field)
This clears the fields smaller than 'field'
(e.g., HOUR_OF_DAY clears MINUTE, SECOND, and MILLISECOND,
but doesn't change HOUR_OF_DAY, MONTH, or YEAR).
|
static java.lang.String |
epochSecondsToLimitedIsoStringT(java.lang.String time_precision,
double seconds,
java.lang.String NaNString)
This is like safeEpochSecondsToIsoStringT3Z, but returns a
limited precision string.
|
static double |
epochSecondsToUnitsSince(double baseSeconds,
double factorToGetSeconds,
double epochSeconds)
This converts an epochSeconds value into a unitsSince value.
|
static java.lang.String |
format(double epochSeconds,
java.lang.String pattern,
java.lang.String zone)
This formats the epochSeconds time value using the pattern.
|
static double[] |
getTimeBaseAndFactor(java.lang.String tsUnits,
java.util.TimeZone timeZone)
This converts a string "[units] since [isoDate]"
(e.g., "minutes since 1985-01-01") into
a baseSeconds (seconds since 1970-01-01) and a factor ("minutes" returns 60).
|
static double |
parseToEpochSeconds(java.lang.String sourceTime,
java.lang.String dateTimeFormat)
A variant of parseToEpochSeconds that uses the Zulu time zone.
|
static double |
parseToEpochSeconds(java.lang.String sourceTime,
java.lang.String dateTimeFormat,
java.lang.String timeZoneString)
This converts a sourceTime string into a double with epochSeconds.
|
static double |
tryToEpochSeconds(java.lang.String someDateTimeString)
This tries to figure out the format of someDateTimeString
then parse the value and convert it to epochSeconds.
|
static java.lang.String |
tryToIsoString(java.lang.String someDateTimeString)
This tries to figure out the format of someDateTimeString
then parse the value and convert to an ISO 8601 string with 'Z' at end.
|
static double |
unitsSinceToEpochSeconds(double baseSeconds,
double factorToGetSeconds,
double unitsSince)
This converts a unitsSince value into epochSeconds.
|
public static final int ERA
public static final int BC
public static final int YEAR
public static final int MONTH
public static final int DATE
public static final int DAY_OF_YEAR
public static final int HOUR
public static final int HOUR_OF_DAY
public static final int MINUTE
public static final int SECOND
public static final int MILLISECOND
public static final int AM_PM
public static final int ZONE_OFFSET
public static final int DST_OFFSET
public static double[] getTimeBaseAndFactor(java.lang.String tsUnits, java.util.TimeZone timeZone)
WARNING: don't use the equations above. Use unitsSinceToEpochSeconds or epochSecondsToUnitsSince which correctly handle special cases.
tsUnits
- e.g., "minutes since 1985-01-01".
This may include hours, minutes, seconds, decimal, and Z or timezone offset (default=Zulu).
This is lenient.timeZone
- Is a TimeZone from TimeZone.gettimeZone(id).
For valid ID's, see the "TZ database names" column in the table at
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
If this is null, Zulu will be used.java.lang.RuntimeException
- if trouble (tsUnits is null or invalid)public static double unitsSinceToEpochSeconds(double baseSeconds, double factorToGetSeconds, double unitsSince)
baseSeconds
- from getTimeBaseAndFactor[0]factorToGetSeconds
- from getTimeBaseAndFactor[1]unitsSince
- a numeric time value in source units "units since baseTime"public static double epochSecondsToUnitsSince(double baseSeconds, double factorToGetSeconds, double epochSeconds)
baseSeconds
- from getTimeBaseAndFactor[0]factorToGetSeconds
- from getTimeBaseAndFactor[1]epochSeconds
- seconds since 1970-01-01 (or NaN if epochSeconds is NaN)public static double parseToEpochSeconds(java.lang.String sourceTime, java.lang.String dateTimeFormat, java.lang.String timeZoneString)
sourceTime
- a formatted time stringdateTimeFormat
- See
https://erddap.github.io/setupDatasetsXml.html#stringTimeUnitstimeZoneString
- For a list of valid timezone ID's,
see the "TZ database names" column in the table at
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones .
If this is null or "", Zulu will be used.public static double parseToEpochSeconds(java.lang.String sourceTime, java.lang.String dateTimeFormat)
sourceTime
- a formatted time stringdateTimeFormat
- See
https://erddap.github.io/setupDatasetsXml.html#stringTimeUnitspublic static double tryToEpochSeconds(java.lang.String someDateTimeString)
someDateTimeString
- a formatted time stringpublic static java.lang.String tryToIsoString(java.lang.String someDateTimeString)
someDateTimeString
- public static java.lang.String format(double epochSeconds, java.lang.String pattern, java.lang.String zone)
epochSeconds
- pattern
- see
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
If pattern is null or "", this uses the ISO TZ format with seconds precision.zone
- if null or "", Zulu is usedpublic static java.lang.String epochSecondsToLimitedIsoStringT(java.lang.String time_precision, double seconds, java.lang.String NaNString)
time_precision
- can be "1970", "1970-01", "1970-01-01", "1970-01-01T00Z",
"1970-01-01T00:00Z", "1970-01-01T00:00:00Z" (used if time_precision not matched),
"1970-01-01T00:00:00.0Z", "1970-01-01T00:00:00.00Z", "1970-01-01T00:00:00.000Z".
Or any of those without "Z".
If time_precision ends in Z, the result will too.
If time_precision doesn't end in Z, the result won't end in Z.
Note that ERDDAP™ requires/forces/ensures any format with hours(min(sec)) to have Z.seconds
- the epochSeconds valueNaNString
- the value to return if seconds is not finite or is too big.public static double clearSmallerFields(double epochSeconds, int field)
epochSeconds
- field
- e.g., HOUR_OF_DAY