Class CBORDateConverter
- All Implemented Interfaces:
ICBORConverter<Date>,ICBORToFromConverter<Date>
A class for converting date-time objects to and from tagged CBOR objects.
In this class's documentation, the "number of seconds since the start of 1970" is based on the POSIX definition of "seconds since the Epoch", a definition that does not count leap seconds. This number of seconds assumes the use of a proleptic Gregorian calendar, in which the rules regarding the number of days in each month and which years are leap years are the same for all years as they were in 1970 (including without regard to time zone differences or transitions from other calendars to the Gregorian).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumConversion type for date-time conversion. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CBORDateConverterA converter object where FromCBORObject accepts CBOR objects with tag 0 (date/time strings) and tag 1 (number of seconds since the start of 1970), and ToCBORObject converts date/time objects (java.util.Date in DotNet, and Date in Java) to CBOR objects of tag 1.static final CBORDateConverterA converter object where FromCBORObject accepts CBOR objects with tag 0 (date/time strings) and tag 1 (number of seconds since the start of 1970), and ToCBORObject converts date/time objects (java.util.Date in DotNet, and Date in Java) to CBOR objects of tag 0.static final CBORDateConverterA converter object where FromCBORObject accepts untagged CBOR integer or CBOR floating-point objects that give the number of seconds since the start of 1970, and where ToCBORObject converts date/time objects (java.util.Date in DotNet, and Date in Java) to such untagged CBOR objects. -
Constructor Summary
ConstructorsConstructorDescriptionInitializes a new instance of theCBORDateConverterclass.Initializes a new instance of theCBORDateConverterclass. -
Method Summary
Modifier and TypeMethodDescriptionDateTimeFieldsToCBORObject(int year, int[] lesserFields) Converts a date/time in the form of a year, month, day, hour, minute, second, fractional seconds, and time offset to a CBOR object.DateTimeFieldsToCBORObject(int smallYear, int month, int day) Converts a date/time in the form of a year, month, and day to a CBOR object.DateTimeFieldsToCBORObject(int smallYear, int month, int day, int hour, int minute, int second) Converts a date/time in the form of a year, month, day, hour, minute, and second to a CBOR object.DateTimeFieldsToCBORObject(com.upokecenter.numbers.EInteger bigYear, int[] lesserFields) Converts a date/time in the form of a year, month, day, hour, minute, second, fractional seconds, and time offset to a CBOR object.FromCBORObject(CBORObject obj) Converts a CBOR object to a java.util.Date (in DotNet) or a Date (in Java).getType()Gets the conversion type for this date converter.ToCBORObject(Date obj) Converts a java.util.Date (in DotNet) or Date (in Java) to a CBOR object in a manner specified by this converter's conversion type.booleanTryGetDateTimeFields(CBORObject obj, com.upokecenter.numbers.EInteger[] year, int[] lesserFields) Tries to extract the fields of a date and time in the form of a CBOR object.
-
Field Details
-
TaggedString
A converter object where FromCBORObject accepts CBOR objects with tag 0 (date/time strings) and tag 1 (number of seconds since the start of 1970), and ToCBORObject converts date/time objects (java.util.Date in DotNet, and Date in Java) to CBOR objects of tag 0. -
TaggedNumber
A converter object where FromCBORObject accepts CBOR objects with tag 0 (date/time strings) and tag 1 (number of seconds since the start of 1970), and ToCBORObject converts date/time objects (java.util.Date in DotNet, and Date in Java) to CBOR objects of tag 1. The ToCBORObject conversion is lossless only if the number of seconds since the start of 1970 can be represented exactly as an integer in the interval [-(2^64), 2^64 - 1] or as a 64-bit floating-point number in the IEEE 754r binary64 format; the conversion is lossy otherwise. The ToCBORObject conversion will throw an exception if the conversion to binary64 results in positive infinity, negative infinity, or not-a-number. -
UntaggedNumber
A converter object where FromCBORObject accepts untagged CBOR integer or CBOR floating-point objects that give the number of seconds since the start of 1970, and where ToCBORObject converts date/time objects (java.util.Date in DotNet, and Date in Java) to such untagged CBOR objects. The ToCBORObject conversion is lossless only if the number of seconds since the start of 1970 can be represented exactly as an integer in the interval [-(2^64), 2^64 - 1] or as a 64-bit floating-point number in the IEEE 754r binary64 format; the conversion is lossy otherwise. The ToCBORObject conversion will throw an exception if the conversion to binary64 results in positive infinity, negative infinity, or not-a-number.
-
-
Constructor Details
-
CBORDateConverter
public CBORDateConverter()Initializes a new instance of theCBORDateConverterclass. -
CBORDateConverter
Initializes a new instance of theCBORDateConverterclass.- Parameters:
convType- Conversion type giving the rules for converting dates and times to and from CBOR objects.
-
-
Method Details
-
getType
Gets the conversion type for this date converter.- Returns:
- The conversion type for this date converter.
-
FromCBORObject
Converts a CBOR object to a java.util.Date (in DotNet) or a Date (in Java).- Specified by:
FromCBORObjectin interfaceICBORToFromConverter<Date>- Parameters:
obj- A CBOR object that specifies a date/time according to the conversion type used to create this date converter.- Returns:
- A java.util.Date or Date that encodes the date/time specified in the CBOR object.
- Throws:
NullPointerException- The parameterobjis null.CBORException- The format of the CBOR object is not supported, or another error occurred in conversion.
-
TryGetDateTimeFields
public boolean TryGetDateTimeFields(CBORObject obj, com.upokecenter.numbers.EInteger[] year, int[] lesserFields) Tries to extract the fields of a date and time in the form of a CBOR object.- Parameters:
obj- A CBOR object that specifies a date/time according to the conversion type used to create this date converter.year- An array whose first element will store the year. The array's length must be 1 or greater. If this function fails, the first element is set to null.lesserFields-An array that will store the fields (other than the year) of the date and time. The array's length must be 7 or greater. If this function fails, the first seven elements are set to 0. If this method is successful, the first seven elements of the array (starting at 0) will be as follows:
- 0 - Month of the year, from 1 (January) through 12 (December).
- 1 - Day of the month, from 1 through 31.
- 2 - Hour of the day, from 0 through 23.
- 3 - Minute of the hour, from 0 through 59.
- 4 - Second of the minute, from 0 through 59.
- 5 - Fractional seconds, expressed in nanoseconds. This value cannot be less than 0 and must be less than 1000*1000*1000.
- 6 - Number of minutes to subtract from this date and time to get global time. This number can be positive or negative, but cannot be less than -1439 or greater than 1439. For tags 0 and 1, this value is always 0.
- Returns:
- Either
trueif the method is successful, orfalseotherwise. - Throws:
NullPointerException- The parameteryearorlesserFieldsis null, or contains fewer elements than required.
-
DateTimeFieldsToCBORObject
Converts a date/time in the form of a year, month, and day to a CBOR object. The hour, minute, and second are treated as 00:00:00 by this method, and the time offset is treated as 0 by this method.- Parameters:
smallYear- The year.month- Month of the year, from 1 (January) through 12 (December).day- Day of the month, from 1 through 31.- Returns:
- A CBOR object encoding the given date fields according to the conversion type used to create this date converter.
- Throws:
CBORException- An error occurred in conversion.
-
DateTimeFieldsToCBORObject
public CBORObject DateTimeFieldsToCBORObject(int smallYear, int month, int day, int hour, int minute, int second) Converts a date/time in the form of a year, month, day, hour, minute, and second to a CBOR object. The time offset is treated as 0 by this method.- Parameters:
smallYear- The year.month- Month of the year, from 1 (January) through 12 (December).day- Day of the month, from 1 through 31.hour- Hour of the day, from 0 through 23.minute- Minute of the hour, from 0 through 59.second- Second of the minute, from 0 through 59.- Returns:
- A CBOR object encoding the given date fields according to the conversion type used to create this date converter.
- Throws:
CBORException- An error occurred in conversion.
-
DateTimeFieldsToCBORObject
Converts a date/time in the form of a year, month, day, hour, minute, second, fractional seconds, and time offset to a CBOR object.- Parameters:
year- The year.lesserFields- An array that will store the fields (other than the year) of the date and time. See the TryGetDateTimeFields method for information on the "lesserFields" parameter.- Returns:
- A CBOR object encoding the given date fields according to the conversion type used to create this date converter.
- Throws:
NullPointerException- The parameterlesserFieldsis null.CBORException- An error occurred in conversion.
-
DateTimeFieldsToCBORObject
public CBORObject DateTimeFieldsToCBORObject(com.upokecenter.numbers.EInteger bigYear, int[] lesserFields) Converts a date/time in the form of a year, month, day, hour, minute, second, fractional seconds, and time offset to a CBOR object.- Parameters:
bigYear- The year.lesserFields- An array that will store the fields (other than the year) of the date and time. See the TryGetDateTimeFields method for information on the "lesserFields" parameter.- Returns:
- A CBOR object encoding the given date fields according to the conversion type used to create this date converter.
- Throws:
NullPointerException- The parameterbigYearorlesserFieldsis null.CBORException- An error occurred in conversion.
-
ToCBORObject
Converts a java.util.Date (in DotNet) or Date (in Java) to a CBOR object in a manner specified by this converter's conversion type.- Specified by:
ToCBORObjectin interfaceICBORConverter<Date>- Parameters:
obj- The parameterobjis a java.util.Date object.- Returns:
- A CBOR object encoding the date/time in the java.util.Date or Date according to the conversion type used to create this date converter.
- Throws:
CBORException- An error occurred in conversion.
-