public string Format(Interval value) { var start = value.HasStart ? InstantPattern.Format(value.Start) : string.Empty; var end = value.HasEnd ? InstantPattern.Format(value.End) : string.Empty; return($"{start}/{end}"); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string)) { return(_pattern.Format((Instant)value)); } if (destinationType == typeof(DateTime)) { return(((Instant)value).ToDateTimeUtc()); } return(base.ConvertTo(context, culture, value, destinationType)); }
public override object?Serialize(object value) { if (value == null) { return(null); } if (value is Instant instant) { return(pattern.Format(instant)); } throw new ArgumentException("The specified value cannot be serialized by the StringType."); }
public DynamoDBEntry ToEntry(object value) { if (null == value) { return(new DynamoDBNull()); } if (!(value is Instant inst)) { throw new ArgumentException("Can only convert Instants"); } return(new Primitive { Value = pattern.Format(inst) }); }
private static void DumpZone(DateTimeZone zone, TextWriter output, int fromYear, int toYear) { output.WriteLine(zone.Id); var start = Instant.FromUtc(fromYear, 1, 1, 0, 0); // Exclusive upper bound var end = Instant.FromUtc(toYear + 1, 1, 1, 0, 0); foreach (var interval in zone.GetZoneIntervals(start, end)) { output.WriteLine("{0} {1} {2}", DateTimePattern.Format(Instant.Max(start, interval.Start)), OffsetPattern.Format(interval.StandardOffset), OffsetPattern.Format(interval.Savings)); } output.WriteLine(); }
/// <summary> /// Serializes the <see cref="Instant"/> for SQL Server queries. /// </summary> /// <param name="instant">An instant.</param> /// <param name="decimalPlaces">Number of digits after the decimal. Must be between 0 and 7 (both included).</param> /// <returns>A SQL formatted string representation of <paramref name="instant"/>.</returns> /// <seealso cref="ToQuotedSqlString(Instant)"/> public static string ToSqlString(this Instant instant, int decimalPlaces) { if (decimalPlaces < 0 || 7 < decimalPlaces) { throw new ArgumentOutOfRangeException(nameof(decimalPlaces), "Value must be between 0 and 7 (both included)."); } if (instant.InUtc().TimeOfDay == LocalTime.Midnight) { return(PatternWithoutTime.Format(instant)); } if (decimalPlaces == 7) { return(PatternWithSevenDecimalPlaces.Format(instant)); } if (decimalPlaces == 0) { return(PatternWithNoDecimalPlaces.Format(instant)); } return(InstantPattern.CreateWithInvariantCulture(@"yyyy'-'MM'-'dd HH':'mm':'ss." + new string('F', decimalPlaces)).Format(instant)); }
public void FormatPatternWithNonTruncatedTicks() { PatternWithNonTruncatedTicks.Format(SampleWithTicks); }
public void GeneralPatternFormat() { GeneralPattern.Format(Sample); }
public static string RenderTimestamp(this IHtmlHelper helper, Instant?instant) => instant == null ? null : instantPattern.Format(instant.Value);
public void NumberPatternFormat() { NumberPattern.Format(Sample); }
private string Serialize(JobProgress progress) { return(_instantPattern.Format(progress.NextIterationStart) + "|" + _instantPattern.Format(progress.NextIterationEnd) + "|" + (progress.NextToken ?? string.Empty)); }