public final class Instance
extends java.lang.Object
Storing the values of an instance in a single long allows to compare them quickly and it doesn't require any object instantiations.
Note that the instance value alone doesn't say much without the corresponding CalendarMetrics and TimeZone.
Also note: never persist packed instance values. The implementation and the format of the packed long may change.
| Modifier and Type | Method and Description |
|---|---|
static int |
dayOfMonth(long instance)
Get the day of month of the given packed instance.
|
static int |
dayOfWeek(long instance)
Get the day of week stored in the packed instance.
|
static int |
hour(long instance)
Get the hour of the given packed instance.
|
static long |
make(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second)
Return an instance value for the given date and time.
|
static long |
make(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second,
int dayOfWeek)
Return an instance value for the given date and time.
|
static long |
maskWeekday(long instance)
Masks the day of week value of the given instance.
|
static int |
minute(long instance)
Get the minute of the given packed instance.
|
static int |
month(long instance)
Get the month of the given packed instance.
|
static int |
second(long instance)
Get the seconds of the given packed instance.
|
static long |
setDayOfMonth(long instance,
int dayOfMonth)
Update the day of month of the given instance.
|
static long |
setDayOfWeek(long instance,
int dayOfWeek)
Update the day of week of the given instance.
|
static long |
setHour(long instance,
int hour)
Update the hour of the given instance.
|
static long |
setMinute(long instance,
int minute)
Update the minute of the given instance.
|
static long |
setMonth(long instance,
int month)
Update the month of the given instance.
|
static long |
setMonthAndDayOfMonth(long instance,
int month,
int dayOfMonth)
Update the month and day of month of the given instance.
|
static long |
setSecond(long instance,
int second)
Update the seconds of the given instance.
|
static long |
setYear(long instance,
int year)
Update the year of the given instance.
|
static java.lang.String |
toString(long instance)
Convert the given instance to a String that conforms to RFC 5545, Section 3.3.5.
|
static java.lang.String |
toString(long instance,
boolean dateOnly)
Convert the given instance to a String that conforms to RFC 5545, Section 3.3.5.
|
static void |
writeTo(java.lang.StringBuilder out,
long instance)
Write a string representation of the given instance that conforms to RFC 5545, Section
3.3.5 to a
StringBuilder. |
static void |
writeTo(java.lang.StringBuilder out,
long instance,
boolean dateOnly)
Write a string representation of the given instance that conforms to RFC 5545, Section
3.3.5 to a
StringBuilder. |
static void |
writeTo(java.io.Writer out,
long instance)
Write a string representation of the given instance that conforms to RFC 5545, Section
3.3.5 to a
Writer. |
static void |
writeTo(java.io.Writer out,
long instance,
boolean dateOnly)
Write a string representation of the given instance that conforms to RFC 5545, Section
3.3.5 to a
Writer. |
static int |
year(long instance)
Get the year of the given packed instance.
|
public static long make(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second,
int dayOfWeek)
year - The year of the instance.month - The month of the instance.dayOfMonth - The day of the instance.hour - The hour of the instance.minute - The minutes of the instance.second - The seconds of the instance.dayOfWeek - The day of the week of the instance.public static long make(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second)
year - The year of the instance.month - The month of the instance.dayOfMonth - The day of the instance.hour - The hour of the instance.minute - The minutes of the instance.second - The seconds of the instance.public static long setYear(long instance,
int year)
instance - The instance to update.year - The new year.public static long setMonth(long instance,
int month)
instance - The instance to update.month - The new month.public static long setDayOfMonth(long instance,
int dayOfMonth)
instance - The instance to update.dayOfMonth - The new day of month value.public static long setDayOfWeek(long instance,
int dayOfWeek)
instance - The instance to update.dayOfWeek - The new day of week value.public static long setMonthAndDayOfMonth(long instance,
int month,
int dayOfMonth)
setMonth(long, int) and setDayOfMonth(long,
int), just shorter.instance - The instance to update.month - The new month value.dayOfMonth - The new day of month value.public static long setHour(long instance,
int hour)
instance - The instance to update.hour - The new hour value.public static long setMinute(long instance,
int minute)
instance - The instance to update.minute - The new minute value.public static long setSecond(long instance,
int second)
instance - The instance to update.second - The new seconds value.public static long maskWeekday(long instance)
0.instance - The instance to mask.public static int year(long instance)
instance - The instance.public static int month(long instance)
instance - The instance.public static int dayOfMonth(long instance)
instance - The instance.public static int hour(long instance)
instance - The instance.public static int minute(long instance)
instance - The instance.public static int second(long instance)
instance - The instance.public static int dayOfWeek(long instance)
CalendarMetrics.getDayOfWeek(int, int, int) to get the actual day of week.
Values are from 0-6 where 0 means Sunday and 6 means Saturday. Note that this is different from the values the Calendar class uses.
instance - The instance.public static java.lang.String toString(long instance)
Convert the given instance to a String that conforms to RFC 5545, Section 3.3.5.
20150304T203000
instance - An instance value.toString(long, boolean)public static java.lang.String toString(long instance,
boolean dateOnly)
Convert the given instance to a String that conforms to RFC 5545, Section 3.3.5. This method has a parameter to tell whether the time part should be included or not.
dateOnly == false: 20150304T203000 dateOnly == true: 20150304
instance - An instance value.dateOnly - true to return the date value only, false to also append the time.toString(long)public static void writeTo(java.lang.StringBuilder out,
long instance)
Write a string representation of the given instance that conforms to RFC 5545, Section
3.3.5 to a StringBuilder. This method always writes a time value. Use writeTo(Writer, long, boolean) to write only the date.
20150304T203000
out - The StringBuilder to write to.instance - An instance value.writeTo(Writer, long, boolean)public static void writeTo(java.lang.StringBuilder out,
long instance,
boolean dateOnly)
Write a string representation of the given instance that conforms to RFC 5545, Section
3.3.5 to a StringBuilder. This method has a parameter to tell whether the time part should be written or not.
dateOnly == false: 20150304T203000 dateOnly == true: 20150304
out - The StringBuilder to write to.instance - An instance value.dateOnly - true to write the date value only, false to also write the time.writeTo(StringBuilder, long)public static void writeTo(java.io.Writer out,
long instance)
throws java.io.IOException
Write a string representation of the given instance that conforms to RFC 5545, Section
3.3.5 to a Writer. This method always writes a time value. Use writeTo(Writer, long, boolean) to write only the date.
20150304T203000
out - The Writer to write to.instance - An instance value.java.io.IOExceptionwriteTo(Writer, long, boolean)public static void writeTo(java.io.Writer out,
long instance,
boolean dateOnly)
throws java.io.IOException
Write a string representation of the given instance that conforms to RFC 5545, Section
3.3.5 to a Writer. This method has a parameter to tell whether the time part should be written or not.
dateOnly == false: 20150304T203000 dateOnly == true: 20150304
out - The Writer to write to.instance - An instance value.dateOnly - true to write the date value only, false to also write the time.java.io.IOExceptionwriteTo(Writer, long)