public class WarcDate extends java.lang.Object
Date class has been deprecated.
This class maintains the UTC date time internally along with other fields.
The old implementation just used the Date object directly leaving the timezone mess to the user.
Please note the following:
JDK8 precision is millis. JDK9+ is nano precision.
Converting from DateTime to Date on JDK9+ will therefore give precision errors unless compensated for.
Exampples:
WARC-Date: 2016-01-11T23:24:25.412030Z
WARC-Date: 2016-01-11T23:24:25Z
WARC-Date: 2016-01
Year:
YYYY (eg 1997)
Year and month:
YYYY-MM (eg 1997-07)
Complete date:
YYYY-MM-DD (eg 1997-07-16)
Complete date plus hours and minutes:
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
Complete date plus hours, minutes and seconds:
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
Complete date plus hours, minutes, seconds and a decimal fraction of a second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)| Modifier and Type | Field and Description |
|---|---|
protected static int[] |
asciiInt
internal array used to convert digit to char.
|
int |
dayOfMonth
Day of month (1-31).
|
long |
fraction
Bigger fraction in case someone needs more than nano precision.
|
int |
fractionLen
Length of the fraction string representation.
|
int |
hour
Hour (0-23).
|
java.time.LocalDateTime |
ldt
Object used to convert dates, handle timezones and retrieve fields.
|
int |
minute
Minute (0-59).
|
int |
month
Month (1-12).
|
int |
nanoOfSecond
Nano of second (0-999.999.999).
|
static int |
P_DAYOFMONTH
Day of month level precision.
|
static int |
P_FRACTION
Nano/fraction level precision.
|
static int |
P_MINUTE
Minute level precision.
|
static int |
P_MONTH
Month level precision.
|
static int |
P_SECOND
Second level precision.
|
static int |
P_YEAR
Year level precision.
|
int |
precision
Precision level of the warc date (year to fraction).
|
int |
second
Second (0-59).
|
protected static java.util.TimeZone |
UTC_TIMEZONE
UTC
TimeZone object for reuse. |
int |
year
Year.
|
| Constructor and Description |
|---|
WarcDate(int year)
Construct
WarcDate with year level precision. |
WarcDate(int year,
int month)
Construct
WarcDate with month level precision. |
WarcDate(int year,
int month,
int dayOfMonth)
Create
WarcDate with day of month level precision. |
WarcDate(int year,
int month,
int dayOfMonth,
int hour,
int minute)
Create
WarcDate with minute level precision. |
WarcDate(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second)
Create
WarcDate with second level precision. |
WarcDate(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second,
int nanoOfSecond)
Create
WarcDate with nano if second level precision. |
WarcDate(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second,
int nanoOfSecond,
long fraction,
int fractionLen)
Create
WarcDate with nano if second level precision. |
WarcDate(java.time.LocalDateTime ldt)
Create
WarcDate with nano if second level precision. |
| Modifier and Type | Method and Description |
|---|---|
void |
adjustPrecisionTo(int newPrecision)
Adjust the precision and initialize the appropriate fields.
|
java.lang.String |
debugString()
For debugging purposes you can get a string of the internal fields and their values.
|
boolean |
equals(java.lang.Object obj) |
static WarcDate |
fromLocalDate(java.util.Date date)
Returns a
WarcDate object from on a Date in the default system timezone. |
static WarcDate |
fromUTCDate(java.util.Date date)
Returns a
WarcDate object from on a Date in the default system timezone. |
java.util.Date |
getDateLocal()
Returns a
Date representing the internal date time adjusted to the system default timezone. |
java.util.Date |
getDateUTC()
Returns a
Date representing the internal date time (UTC timezone). |
static WarcDate |
getWarcDate(byte[] bytes,
int pos,
int limit)
Attempt to parse a WARC date string from a byte array in a subset of the W3CDTF format.
|
static WarcDate |
getWarcDate(java.lang.String datestring)
Attempt to parse a WARC date string in a subset of the W3CDTF format.
|
int |
hashCode() |
static WarcDate |
now()
Returns a
WarcDate representing the current UTC date time. |
java.lang.String |
toString() |
void |
trimToMillis()
Adjust internal state to millisecond precision.
|
protected static java.util.TimeZone UTC_TIMEZONE
TimeZone object for reuse.protected static int[] asciiInt
public static final int P_YEAR
public static final int P_MONTH
public static final int P_DAYOFMONTH
public static final int P_MINUTE
public static final int P_SECOND
public static final int P_FRACTION
public java.time.LocalDateTime ldt
public int precision
public int year
public int month
public int dayOfMonth
public int hour
public int minute
public int second
public int nanoOfSecond
public long fraction
public int fractionLen
public WarcDate(int year)
WarcDate with year level precision.year - yearpublic WarcDate(int year, int month)
WarcDate with month level precision.year - yearmonth - integer between 1 and 12public WarcDate(int year, int month, int dayOfMonth)
WarcDate with day of month level precision.year - yearmonth - integer between 1 and 12dayOfMonth - integer between 1 and 31public WarcDate(int year, int month, int dayOfMonth, int hour, int minute)
WarcDate with minute level precision.year - yearmonth - integer between 1 and 12dayOfMonth - integer between 1 and 31hour - integer between 0 and 59minute - integer between 0 and 59public WarcDate(int year, int month, int dayOfMonth, int hour, int minute, int second)
WarcDate with second level precision.year - yearmonth - integer between 1 and 12dayOfMonth - integer between 1 and 31hour - integer between 0 and 59minute - integer between 0 and 59second - integer between 0 and 59public WarcDate(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)
WarcDate with nano if second level precision.
Nano of second is used with the internal LocalDateTime object.year - yearmonth - integer between 1 and 12dayOfMonth - integer between 1 and 31hour - integer between 0 and 59minute - integer between 0 and 59second - integer between 0 and 59nanoOfSecond - integer between 0 and 999.999.999.public WarcDate(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, long fraction, int fractionLen)
WarcDate with nano if second level precision.
Nano of second is used with the internal LocalDateTime object.
Even though nano of second is currently the limit in Java this implementation can
parse, store and ouput the fraction part as an long value.year - yearmonth - integer between 1 and 12dayOfMonth - integer between 1 and 31hour - integer between 0 and 59minute - integer between 0 and 59second - integer between 0 and 59nanoOfSecond - integer between 0 and 999999999.fraction - long fraction between 0 and 9223372036854775807.fractionLen - franction length to output when converting to a string representationpublic WarcDate(java.time.LocalDateTime ldt)
WarcDate with nano if second level precision.
Nano of second is used with the internal LocalDateTime object.
Do not reuse the LocalDateTime instance!
Nano of second is used with the internal LocalDateTime object.ldt - keep this object internally and use it valuespublic static WarcDate now()
WarcDate representing the current UTC date time.WarcDate representing the current UTC date timepublic static WarcDate fromLocalDate(java.util.Date date)
WarcDate object from on a Date in the default system timezone.date - date in the system default timezone (technically deprecated)WarcDate objectpublic java.util.Date getDateLocal()
Date representing the internal date time adjusted to the system default timezone.Date representing the internal date time adjusted to the system default timezonepublic static WarcDate fromUTCDate(java.util.Date date)
WarcDate object from on a Date in the default system timezone.date - date in the system default timezone (technically deprecated)WarcDate objectpublic java.util.Date getDateUTC()
Date representing the internal date time (UTC timezone).Date representing the internal date time (UTC timezone)public static WarcDate getWarcDate(java.lang.String datestring)
datestring - WARC date stringWarcDate objectpublic static WarcDate getWarcDate(byte[] bytes, int pos, int limit)
bytes - WARC date string as a byte arraypos - start position in the byte arraylimit - limit in the byte arrayWarcDate objectpublic void trimToMillis()
public void adjustPrecisionTo(int newPrecision)
newPrecision - the new precisionpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String debugString()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.ObjectCopyright © 2011–2023. All rights reserved.