Exemplo n.º 1
0
 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is null)
     {
         return(UnsetValue);
     }
     if (!(value is ZonedDateTime zdt))
     {
         throw new NotImplementedException();
     }
     return(pattern.Format(zdt));
 }
Exemplo n.º 2
0
        public DynamoDBEntry ToEntry(object value)
        {
            if (null == value)
            {
                return(new DynamoDBNull());
            }
            if (!(value is ZonedDateTime zoned))
            {
                throw new ArgumentException("Can only convert ZonedDateTimes");
            }

            return(new Primitive
            {
                Value = pattern.Format(zoned)
            });
        }
Exemplo n.º 3
0
        public static string TimeString(Variable input)
        {
            if (input.ZoneDateTimeVal.HasValue)
            {
                return(_zoneTmPattern.Format(input.ZoneDateTimeVal.Value));
            }

            if (input.TimeVal.HasValue)
            {
                //return OffsetTimePattern.Rfc3339.Format (input.TimeVal.Value);
                return(_offsetTimePatternWithSecondsOffset.Format(input.TimeVal.Value));
            }

            if (input.LocalTimeVal.HasValue)
            {
                return(LocalTimePattern.ExtendedIso.Format(input.LocalTimeVal.Value));
            }
            return(null);
        }
Exemplo n.º 4
0
        public static string DateTimeString(Variable input)
        {
            if (input.ZoneDateTimeVal.HasValue)
            {
                return(_zoneDtPattern.Format(input.ZoneDateTimeVal.Value));
            }

            if (input.DateTimeVal.HasValue)
            {
                return(OffsetDateTimePattern.Rfc3339.Format(input.DateTimeVal.Value));
            }

            if (input.LocalDateTimeVal.HasValue)
            {
                return(LocalDateTimePattern.ExtendedIso.Format(input.LocalDateTimeVal.Value));
            }

            return(null);
        }
        public async Task <HistoricalCalendarDataResponse> fetchHistoricalCalendarData(long siteId,
                                                                                       LocalDate dayInDesiredMonth, DateTimeZone reportTimeZone, TeslaAuthToken authToken)
        {
            ZonedDateTime endOfMonth = getEndOfMonth(dayInDesiredMonth, reportTimeZone);
            UriBuilder    uri        = OwnerApiClientImpl.apiRoot
                                       .WithPathSegment("energy_sites")
                                       .WithPathSegment(siteId.ToString())
                                       .WithPathSegment("calendar_history")
                                       .WithParameter("kind", "energy")
                                       .WithParameter("period", "month")
                                       .WithParameter("end_date", ISO_8601_DATETIME_MILLIS_ZONE.Format(endOfMonth));

            try {
                HttpRequestMessage request = OwnerApiClientImpl.createRequest(HttpMethod.Get, uri, authToken);
                using HttpResponseMessage response = await httpClient.SendAsync(request);

                var historicalCalendarData = await readContentAsJson <HistoricalCalendarData>(response);

                return(historicalCalendarData.response);
            } catch (HttpRequestException e) {
                throw new TeslaException($"Failed to get historical solar calendar data for the month ending on {endOfMonth}", e);
            }
        }
    public bool TryDestructure(object value, ILogEventPropertyValueFactory _, out LogEventPropertyValue?result)
    {
        if (value is Instant instant1)
        {
            result = new ScalarValue(InstantPattern.ExtendedIso.Format(instant1));
            return(true);
        }

        if (value is LocalDateTime localDateTime)
        {
            result = new ScalarValue(LocalDateTimePattern.ExtendedIso.Format(localDateTime));
            return(true);
        }

        if (value is LocalDate localDate)
        {
            result = new ScalarValue(LocalDatePattern.Iso.Format(localDate));
            return(true);
        }

        if (value is LocalTime localTime)
        {
            result = new ScalarValue(LocalTimePattern.ExtendedIso.Format(localTime));
            return(true);
        }

        if (value is OffsetDateTime offsetDateTime)
        {
            result = new ScalarValue(OffsetDateTimePattern.ExtendedIso.Format(offsetDateTime));
            return(true);
        }

        if (value is OffsetDate offsetDate)
        {
            result = new ScalarValue(OffsetDatePattern.GeneralIso.Format(offsetDate));
            return(true);
        }

        if (value is OffsetTime offsetTime)
        {
            result = new ScalarValue(OffsetTimePattern.ExtendedIso.Format(offsetTime));
            return(true);
        }

        if (value is ZonedDateTime zonedDateTime)
        {
            result = new ScalarValue(_zonedDateTimePattern.Format(zonedDateTime));
            return(true);
        }

        if (value is DateTimeZone dateTimeZone)
        {
            result = new ScalarValue(dateTimeZone.Id);
            return(true);
        }

        if (value is Duration duration)
        {
            result = new ScalarValue(DurationPattern.Roundtrip.Format(duration));
            return(true);
        }

        if (value is Period period)
        {
            result = new ScalarValue(PeriodPattern.NormalizingIso.Format(period));
            return(true);
        }

        if (value is Interval interval)
        {
            var values = new List <LogEventProperty>();
            if (interval.HasStart)
            {
                values.Add(new LogEventProperty("Start", _.CreatePropertyValue(interval.Start)));
            }

            if (interval.HasEnd)
            {
                values.Add(new LogEventProperty("End", _.CreatePropertyValue(interval.End)));
            }

            result = new StructureValue(values);
            return(true);
        }

        result = null;
        return(false);
    }
 protected override string GenerateNonNullSqlLiteral(object value)
 => $"TIMESTAMPTZ '{Pattern.Format((ZonedDateTime)value)}'";
Exemplo n.º 8
0
 internal static string formatDate(ZonedDateTime date)
 {
     return(ISO8601_NO_ZONE_NO_MILLIS_PATTERN.Format(date));
 }
 private string GenerateLiteralCore(object value)
 => Pattern.Format((ZonedDateTime)value);
Exemplo n.º 10
0
 public void FormatWithNumbersToSecond()
 {
     PatternWithNumbersToSecond.Format(SampleZonedDateTime);
 }
Exemplo n.º 11
0
 public static string FormatShort(this Instant instant)
 {
     return(hm.Format(instant.InZone(currentTimezone)));
 }
Exemplo n.º 12
0
 public static string Format(this Instant instant)
 {
     return(shortPattern.Format(instant.InZone(currentTimezone)));
 }