PeterO.Cbor.CBORDateConverter

PeterO.Cbor.CBORDateConverter

public sealed class CBORDateConverter :
    PeterO.Cbor.ICBORConverter,
    PeterO.Cbor.ICBORToFromConverter

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).

Member Summary

CBORDateConverter Constructor

public CBORDateConverter(
    PeterO.Cbor.CBORDateConverter.ConversionType convType);

Initializes a new instance of the PeterO.Cbor.CBORDateConverter class.

Parameters:

CBORDateConverter Constructor

public CBORDateConverter();

Initializes a new instance of the PeterO.Cbor.CBORDateConverter class.

TaggedNumber

public static readonly PeterO.Cbor.CBORDateConverter 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 (DateTime 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.

TaggedString

public static readonly PeterO.Cbor.CBORDateConverter 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 (DateTime in DotNet, and Date in Java) to CBOR objects of tag 0.

UntaggedNumber

public static readonly PeterO.Cbor.CBORDateConverter 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 (DateTime 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.

Type

public PeterO.Cbor.CBORDateConverter.ConversionType Type { get; }

Gets the conversion type for this date converter.

Returns:

The conversion type for this date converter.

DateTimeFieldsToCBORObject

public PeterO.Cbor.CBORObject DateTimeFieldsToCBORObject(
    int smallYear,
    int month,
    int day);

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:

Return Value:

A CBOR object encoding the given date fields according to the conversion type used to create this date converter.

Exceptions:

DateTimeFieldsToCBORObject

public PeterO.Cbor.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:

Return Value:

A CBOR object encoding the given date fields according to the conversion type used to create this date converter.

Exceptions:

DateTimeFieldsToCBORObject

public PeterO.Cbor.CBORObject DateTimeFieldsToCBORObject(
    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.

Parameters:

Return Value:

A CBOR object encoding the given date fields according to the conversion type used to create this date converter.

Exceptions:

DateTimeFieldsToCBORObject

public PeterO.Cbor.CBORObject DateTimeFieldsToCBORObject(
    PeterO.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:

Return Value:

A CBOR object encoding the given date fields according to the conversion type used to create this date converter.

Exceptions:

FromCBORObject

public sealed System.DateTime FromCBORObject(
    PeterO.Cbor.CBORObject obj);

Converts a CBOR object to a DateTime (in DotNet) or a Date (in Java).

Parameters:

Return Value:

A DateTime or Date that encodes the date/time specified in the CBOR object.

Exceptions:

ToCBORObject

public sealed PeterO.Cbor.CBORObject ToCBORObject(
    System.DateTime obj);

Converts a DateTime (in DotNet) or Date (in Java) to a CBOR object in a manner specified by this converter's conversion type.

Parameters:

Return Value:

A CBOR object encoding the date/time in the DateTime or Date according to the conversion type used to create this date converter.

Exceptions:

TryGetDateTimeFields

public bool TryGetDateTimeFields(
    PeterO.Cbor.CBORObject obj,
    PeterO.Numbers.EInteger& year,
    int[] lesserFields);

Tries to extract the fields of a date and time in the form of a CBOR object.

Parameters:

Return Value:

Either true if the method is successful, or false otherwise.

TryGetDateTimeFields

public bool TryGetDateTimeFields(
    PeterO.Cbor.CBORObject obj,
    PeterO.Numbers.EInteger[] year,
    int[] lesserFields);

Tries to extract the fields of a date and time in the form of a CBOR object.

Parameters:

.

Return Value:

Either true if the method is successful, or false otherwise.

Back to CBOR start page.