private static string DateTimeToString(DateTime bi) { var lesserFields = new int[7]; var year = new EInteger[1]; PropertyMap.BreakDownDateTime(bi, year, lesserFields); return(CBORUtilities.ToAtomDateTimeString(year[0], lesserFields)); }
private static string DateTimeToString(DateTime bi) { var lesserFields = new int[7]; var year = new EInteger[1]; PropertyMap.BreakDownDateTime(bi, year, lesserFields); // TODO: Change to true in next major version return(CBORUtilities.ToAtomDateTimeString(year[0], lesserFields, false)); }
private static string DateTimeToString(DateTime bi) { try { var lesserFields = new int[7]; var outYear = new EInteger[1]; PropertyMap.BreakDownDateTime(bi, outYear, lesserFields); return(CBORUtilities.ToAtomDateTimeString(outYear[0], lesserFields)); } catch (ArgumentException ex) { throw new CBORException(ex.Message, ex); } }
/// <summary>Converts a date/time in the form of a year, month, day, /// hour, minute, second, fractional seconds, and time offset to a CBOR /// object.</summary> /// <param name='bigYear'>The parameter <paramref name='bigYear'/> is a /// Numbers.EInteger object.</param> /// <param name='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.</param> /// <returns>A CBOR object encoding the given date fields according to /// the conversion type used to create this date converter.</returns> /// <exception cref='ArgumentNullException'>The parameter <paramref /// name='bigYear'/> or <paramref name='lesserFields'/> is /// null.</exception> /// <exception cref='PeterO.Cbor.CBORException'>An error occurred in /// conversion.</exception> public CBORObject DateTimeFieldsToCBORObject(EInteger bigYear, int[] lesserFields) { if (bigYear == null) { throw new ArgumentNullException(nameof(bigYear)); } if (lesserFields == null) { throw new ArgumentNullException(nameof(lesserFields)); } if (lesserFields.Length < 7) { throw new ArgumentException("\"lesserFields\" + \"'s length\" (" + lesserFields.Length + ") is not greater or equal to 7"); } try { switch (this.convType) { case ConversionType.TaggedString: { string str = CBORUtilities.ToAtomDateTimeString(bigYear, lesserFields); return(CBORObject.FromObjectAndTag(str, 0)); } case ConversionType.TaggedNumber: case ConversionType.UntaggedNumber: try { var status = new int[1]; EFloat ef = CBORUtilities.DateTimeToIntegerOrDouble( bigYear, lesserFields, status); if (status[0] == 0) { return(this.convType == ConversionType.TaggedNumber ? CBORObject.FromObjectAndTag(ef.ToEInteger(), 1) : CBORObject.FromObject(ef.ToEInteger())); } else if (status[0] == 1) { return(this.convType == ConversionType.TaggedNumber ? CBORObject.FromFloatingPointBits(ef.ToDoubleBits(), 8).WithTag(1) : CBORObject.FromFloatingPointBits(ef.ToDoubleBits(), 8)); } else { throw new CBORException("Too big or small to fit an integer" + "\u0020or" + "\u0020floating-point number"); } } catch (ArgumentException ex) { throw new CBORException(ex.Message, ex); } default: throw new CBORException("Internal error"); } } catch (ArgumentException ex) { throw new CBORException(ex.Message, ex); } }