public static uint GetNewYorkTimestamp(DateTimeOffset offset) { return((uint)(ZonedDateTime.FromDateTimeOffset(offset) .WithZone(EasternTimeZone) .ToDateTimeUnspecified() - DateTime.UnixEpoch).TotalSeconds); }
private object ConvertTicksToDateTime( SensorDataTableEntity source, SensorData destination, string destMember, ResolutionContext context) { if (string.IsNullOrWhiteSpace(source.RowKey)) { return(null); } context.Items.TryGetValue("DateTimeZone", out var ianaTimeZone); var dateTimeZone = ianaTimeZone as DateTimeZone; if (dateTimeZone == null) { return(null); } var rowTicks = source.RowKey; DateTime dateTime = new DateTime(); if (long.TryParse(rowTicks, out var ticks)) { dateTime = new DateTime(ticks, DateTimeKind.Utc); } var zonedDateTime = ZonedDateTime.FromDateTimeOffset(new DateTimeOffset(dateTime, TimeSpan.Zero)); return(zonedDateTime.ToOffsetDateTime().ToString()); }
public async Task ConvertTimeAsync(string targetTimeZone, DateTimeOffset?time = null) { var user = await _db.Users.FindAsync(Context.User.Id); time ??= DateTimeOffset.Now; time = time.Value.ToOffset(user.Timezone ?? TimeSpan.FromHours(8)); var timezone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(targetTimeZone); if (timezone is null) { await ReplyAsync("That is an invalid timezone. Valid timezones are https://en.wikipedia.org/wiki/List_of_tz_database_time_zones under the column 'TZ database name'"); return; } var zonedDate = ZonedDateTime.FromDateTimeOffset(time.Value); var adjusted = zonedDate.WithZone(timezone).ToDateTimeOffset(); if (time.Value.DayOfYear == adjusted.DayOfYear) { await ReplyAsync($"The time {time:**HH:mm**tt GMTz} is {adjusted:**HH:mm**tt GMTz} {timezone}."); } else { await ReplyAsync($"The time {time:ddd, MMM d, **HH:mm**tt GMTz} is {adjusted:ddd, MMM d, **HH:mm**tt GMTz}."); } }
public void ToZonedDateTime_ValidText_Deserialize() { DeserializeAssert( ServiceStackFallbackDeserializers.ToZonedDateTime, "2014/2/21 19:02:13 +05:00", ZonedDateTime.FromDateTimeOffset(new DateTimeOffset(2014, 2, 21, 19, 2, 13, TimeSpan.FromHours(5)))); }
public T Create(T entity) { currentDbcontext.Set <T>().Add(entity); entity.CreatedAt = ZonedDateTime.FromDateTimeOffset(DateTimeOffset.Now); currentDbcontext.SaveChanges(); return(entity); }
/// <summary> /// Attempts to generate a <see cref="ZonedDateTime"/> by deserializing to a <see cref="DateTimeOffset"/> first. /// </summary> /// <param name="text">The JSON to deserialize.</param> /// <returns>The deserialized <see cref="ZonedDateTime"/></returns> /// <exception cref="SerializationException">Failed to deserialize to a <see cref="ZonedDateTime"/></exception> public static ZonedDateTime ToZonedDateTime(string text) { var dateTimeOffset = DeserializeStruct <DateTimeOffset>(text); var zonedDateTime = ZonedDateTime.FromDateTimeOffset(dateTimeOffset); return(zonedDateTime); }
public static ZonedDateTime ToZonedDateTime(string reverseTicks, DateTimeZone dateTimeZone) { var dateTime = ToDateTime(reverseTicks); var zonedDateTime = ZonedDateTime.FromDateTimeOffset(new DateTimeOffset(dateTime, TimeSpan.Zero)); return(zonedDateTime.ToInstant().InZone(dateTimeZone)); }
public T Update(T entity) { currentDbcontext.Set <T>().Update(entity); entity.UpdatedAt = ZonedDateTime.FromDateTimeOffset(DateTimeOffset.Now); currentDbcontext.Entry(entity).Property(p => p.CreatedAt).IsModified = false; currentDbcontext.SaveChanges(); return(entity); }
protected internal string ConvertDateTime(DateTimeOffset offset) { var zoned = ZonedDateTime.FromDateTimeOffset(offset); var tz = Context.ConfigGuild.TimeZone ?? DateTimeZoneProviders.Tzdb["America/Chicago"]; var info = DateTimeFormatInfo.CurrentInfo.FullDateTimePattern; return(zoned.WithZone(tz).ToString(info, null)); }
public void SoftDelete(IdType Id) { var item = findById(Id); item.IsDeleted = true; item.DeletedAt = ZonedDateTime.FromDateTimeOffset(DateTimeOffset.Now); currentDbcontext.Set <T>().Update(item); currentDbcontext.SaveChanges(); }
public void FromDateTimeOffset() { DateTimeOffset dateTimeOffset = new DateTimeOffset(2011, 3, 5, 1, 0, 0, TimeSpan.FromHours(3)); DateTimeZone fixedZone = new FixedDateTimeZone(Offset.FromHours(3)); ZonedDateTime expected = fixedZone.AtStrictly(new LocalDateTime(2011, 3, 5, 1, 0, 0)); ZonedDateTime actual = ZonedDateTime.FromDateTimeOffset(dateTimeOffset); Assert.AreEqual(expected, actual); }
public async Task <IActionResult> GetScheduleEvents(string start, string end) { DateTimeOffset startDateTime, endDateTime; if (DateTimeOffset.TryParse(start, out DateTimeOffset startDt)) { startDateTime = startDt; } else { startDateTime = DateTimeOffset.Now; } if (DateTimeOffset.TryParse(end, out DateTimeOffset endDt)) { endDateTime = endDt; } else { endDateTime = startDateTime.AddMonths(1); } var enrollments = await _context.Enrollments .Include(e => e.Child) .Include(e => e.Subject) .Include(e => e.Teacher) .ToListAsync(); var events = new List <ScheduleEventViewModel>(); foreach (var enrollment in enrollments) { int daysUntilNextOccurrence = ((int)enrollment.TimeslotDayOfWeek - (int)startDateTime.DayOfWeek + 7) % 7; var nextOccurrence = startDateTime.AddDays(daysUntilNextOccurrence); nextOccurrence = new DateTimeOffset(nextOccurrence.Date + new TimeSpan(enrollment.TimeslotTime.Hour, enrollment.TimeslotTime.Minute, 0), nextOccurrence.Offset); int idCounter = 1; do { events.Add(new ScheduleEventViewModel { Id = $"{enrollment.Id}+{idCounter}", Title = $"{enrollment.Subject.Name}: {enrollment.Child.Name} with {enrollment.Teacher.Name}", Start = ZonedDateTime.FromDateTimeOffset(nextOccurrence).ToString("yyyy-MM-ddTHH:mm:sso<g>", CultureInfo.InvariantCulture), End = ZonedDateTime.FromDateTimeOffset(nextOccurrence.AddMinutes(90)).ToString("yyyy-MM-ddTHH:mm:sso<g>", CultureInfo.InvariantCulture), Url = "#" }); nextOccurrence = nextOccurrence.AddDays(7); idCounter++; } while (nextOccurrence <= endDateTime); } return(Ok(events)); }
public void ZonedDateTimeConvertsCorrectlyToDateTimeOffset() { var zdt = ZonedDateTimePattern.CreateWithCurrentCulture("G", DateTimeZoneProviders.Tzdb) .Parse("2020-07-02T11:00:00 UTC-05 (-05)"); Assert.True(zdt.Success); var date = _mapper.Map <DateTimeOffset>(zdt.Value); Assert.Equal(zdt.Value, ZonedDateTime.FromDateTimeOffset(date)); }
public object GetPropertyValue(PropertyInfo property, JToken elementData, CodeFirstResolvingContext context) { var element = (JObject)elementData; var dt = element.Property("value")?.Value?.ToObject <DateTime>(); if (dt != null) { var udt = DateTime.SpecifyKind(dt.Value, DateTimeKind.Utc); ZonedDateTime zdt = ZonedDateTime.FromDateTimeOffset(udt); return(zdt); } return(null); }
protected override async Task CoreAsync(CancellationToken cancellationToken) { var guild = _client.GetGuild(728459950468104284); var phtVc = guild.GetVoiceChannel(PhtVc); var estVc = guild.GetVoiceChannel(EstVc); var streamTitleVc = guild.GetVoiceChannel(StreamTitleVc); var streamVc = guild.GetVoiceChannel(StreamVc); var pht = DateTimeZoneProviders.Tzdb["Asia/Manila"]; var est = DateTimeZoneProviders.Tzdb["Canada/Eastern"]; var time = ZonedDateTime.FromDateTimeOffset(DateTimeOffset.Now); var phtTime = time.WithZone(pht); var estTime = time.WithZone(est); await phtVc.ModifyAsync(v => v.Name = $"{phtTime:ddd, hh:mm tt} PHT"); await estVc.ModifyAsync(v => v.Name = $"{estTime:ddd, hh:mm tt} EST"); var nextStream = await _db.Streams .AsAsyncEnumerable() .OrderBy(s => s.Time) .FirstOrDefaultAsync(s => s.Time > DateTimeOffset.Now); if (nextStream is not null) { var streamTitle = $"【{nextStream.Title}】{nextStream.Platform} in"; if (streamTitleVc.Name != streamTitle) { await streamTitleVc.ModifyAsync(v => v.Name = streamTitle); } // ReSharper disable once ArgumentsStyleLiteral await streamVc.ModifyAsync(v => v.Name = $@" {(nextStream.Time - DateTimeOffset.Now) .Add(TimeSpan.FromMinutes(1)) .Humanize( precision: 2, maxUnit: TimeUnit.Day, minUnit: TimeUnit.Minute )}"); } else { await streamVc.ModifyAsync(v => v.Name = "TBA"); } }
public void Should_WriteZonedDateTimeEntity() { var date = DateTimeOffset.Now; var entity = new ZonedDateTimeEntity() { ZonedDateTime = ZonedDateTime.FromDateTimeOffset(date) }; var tEntity = (ITableEntity)entity; var result = tEntity.WriteEntity(new OperationContext()); result.Should().ContainKey(nameof(ZonedDateTimeEntity.ZonedDateTime)); result[nameof(ZonedDateTimeEntity.ZonedDateTime)].DateTimeOffsetValue.Should().NotBeNull(); result[nameof(ZonedDateTimeEntity.ZonedDateTime)].DateTimeOffsetValue.Should().Be(date); }
public void Should_ReadZonedDateTimeEntity() { var date = DateTimeOffset.Now; var entity = new ZonedDateTimeEntity(); var tEntity = (ITableEntity)entity; tEntity.ReadEntity(new Dictionary <string, EntityProperty> { { nameof(ZonedDateTimeEntity.ZonedDateTime), EntityProperty.GeneratePropertyForString(CustomNodaConverters.ZonedDateTimeFormatter.Format(ZonedDateTime.FromDateTimeOffset(date))) } }, new OperationContext()); entity.ZonedDateTime.Should().Be(ZonedDateTime.FromDateTimeOffset(date)); }
public void Should_ReadZonedDateTimeEntity_FromDateTimeOffset() { var date = DateTimeOffset.Now; var entity = new ZonedDateTimeEntity(); var tEntity = (ITableEntity)entity; tEntity.ReadEntity(new Dictionary <string, EntityProperty> { { nameof(ZonedDateTimeEntity.ZonedDateTime), EntityProperty.GeneratePropertyForDateTimeOffset(date) } }, new OperationContext()); // DateTimeOffset sets to utc time under the covers entity.ZonedDateTime.Should().Be(ZonedDateTime.FromDateTimeOffset(date.UtcDateTime)); }
/// <summary> /// Converts the given object to the type of this converter, using the specified context and culture information. /// </summary> /// <returns> /// An <see cref="T:System.Object"/> that represents the converted value. /// </returns> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context. </param> /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo"/> to use as the current culture. </param> /// <param name="value">The <see cref="T:System.Object"/> to convert. </param> /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { string @string = value as string; if (@string != null) { ZonedDateTime zonedDateTime; if (TimeHelpers.GetZonedDateTimePatterns(culture).TryParseAny(@string.Trim(), out zonedDateTime)) { return(zonedDateTime); } DateTimeOffset dateTimeOffset; if (DateTimeOffset.TryParse(@string, out dateTimeOffset)) { return(ZonedDateTime.FromDateTimeOffset(dateTimeOffset)); } throw new NotSupportedException( // ReSharper disable once AssignNullToNotNullAttribute string.Format(Resources.ZonedDateTimeConverter_ConvertFrom_CannotParse, @string)); } if (value is DateTime) { DateTime dateTime = (DateTime)value; return(ZonedDateTime.FromDateTimeOffset(dateTime.ToUniversalTime())); } if (value is DateTimeOffset) { DateTimeOffset dateTimeOffset = (DateTimeOffset)value; return(ZonedDateTime.FromDateTimeOffset(dateTimeOffset)); } if (value is OffsetDateTime) { OffsetDateTime offsetDateTime = (OffsetDateTime)value; return(offsetDateTime.ToInstant().InUtc()); } if (value is Instant) { Instant instant = (Instant)value; return(instant.InUtc()); } return(base.ConvertFrom(context, culture, value)); }
private void RunTest(JobsWithSchedulesQuery job, Instant targetDate) { Console.WriteLine($"\nJob {job.Id}:\n Date Mode: {job.ScheduleDateMode} = {job.ScheduleDates}\n Time Mode: {job.ScheduleTimeMode} = {job.ScheduleTimes}"); var planner = new TargetPlanner(job, targetDate); var results = planner.GetSchedules(); Console.WriteLine($" Schedules: {results.Count}"); int count = 0; foreach (var s in results) { var zoned = ZonedDateTime.FromDateTimeOffset(s.ScheduleTarget).WithZone(tz); Console.WriteLine($" {ZonedDateTimePattern.ExtendedFormatOnlyIso.Format(zoned)}"); if (++count == 3) { if (results.Count > 3) { Console.WriteLine($" ({results.Count - 3} variations omitted)"); } break; } } }
public async Task Should_Destructure_NodaTime_ZonedDateTime() { using var _ = CaptureLogs(out var logs); Logger.LogInformation("This is just a test {@Data}", ZonedDateTime.FromDateTimeOffset(_clock.GetCurrentInstant().ToDateTimeOffset())); await Verify(logs.Select(z => z.RenderMessage())); }
public void Delete(T entity) { currentDbcontext.Set <T>().Remove(entity); entity.DeletedAt = ZonedDateTime.FromDateTimeOffset(DateTimeOffset.Now); currentDbcontext.SaveChanges(); }
public static DateTimeOffset ToEquipmentLocalTime(this DateTimeOffset utcDateTime, IZoneProvider timezone) { var dateTimeAtSite = ZonedDateTime.FromDateTimeOffset(utcDateTime).WithZone(timezone.DateTimeZone); return(dateTimeAtSite.ToDateTimeOffset()); }
private async Task SendAdjustedDate(DiscordClient c, MessageReactionAddEventArgs e) { if (e.User.IsBot) { return; } if (e.Channel.IsPrivate) { return; } DiscordChannel channel = await c.GetChannelAsync(e.Channel.Id); _ = Task.Run(async() => { if (e.Emoji.Equals(this.ClockEmoji)) { try { DiscordMember reactor = (DiscordMember)e.User; DiscordMessage msg = await channel.GetMessageAsync(e.Message.Id); DbResult <UserTimeZone> opTimeZoneResult = await this.Mediator.Send(new UserTimeZones.GetUsersTimeZone(msg.Author)); if (!opTimeZoneResult.TryGetValue(out UserTimeZone? opTimeZoneEntity)) { await reactor.SendMessageAsync("The original poster has not set up a time zone yet."); return; } string opTimeZoneId = opTimeZoneEntity.TimeZoneId; DateTimeZone?opTimeZone = this.TimeZoneProvider.GetZoneOrNull(opTimeZoneId); DbResult <UserTimeZone> reactorTimeZoneResult = await this.Mediator.Send(new UserTimeZones.GetUsersTimeZone(msg.Author)); if (!reactorTimeZoneResult.TryGetValue(out UserTimeZone? reactorTimeZoneEntity)) { await reactor.SendMessageAsync("You have not set up a time zone yet. Use `time init` to set up your time zone."); return; } string reactorTimeZoneId = reactorTimeZoneEntity.TimeZoneId; DateTimeZone?reactorTimeZone = this.TimeZoneProvider.GetZoneOrNull(reactorTimeZoneId); if (opTimeZone == null || reactorTimeZone == null) { await reactor.SendMessageAsync("There was a problem, please reach out to your bot developer."); return; } ZonedDateTime zonedMessageDateTime = ZonedDateTime.FromDateTimeOffset(msg.CreationTimestamp); DateTime opRefTime = zonedMessageDateTime.WithZone(opTimeZone).ToDateTimeOffset().DateTime; IEnumerable <DateTimeV2ModelResult> parserList = Recognizers.RecognizeDateTime(e.Message.Content, opRefTime, DateTimeV2Type.Time, DateTimeV2Type.DateTime); if (!parserList.Any()) { await reactor.SendMessageAsync("This message does not have a recognizable time in it."); return; } DiscordEmbedBuilder reactorTimeEmbed = new DiscordEmbedBuilder().WithTitle("You requested a timezone conversion"); IEnumerable <(string, DateTimeV2Value)> results = parserList.SelectMany(x => x.Values.Select(y => (x.Text, y))); foreach ((string parsedText, DateTimeV2Value result) in results) { string outputString; if (result.Type is DateTimeV2Type.Time) { LocalTime localParsedTime = (LocalTime)result.Value; LocalDateTime localParsedDateTime = localParsedTime.On(zonedMessageDateTime.LocalDateTime.Date); ZonedDateTime zonedOpDateTime = localParsedDateTime.InZoneStrictly(opTimeZone); ZonedDateTime zonedReactorDateTime = zonedOpDateTime.WithZone(reactorTimeZone); outputString = zonedReactorDateTime.LocalDateTime.TimeOfDay.ToString("t", null); } else { LocalDateTime localParsedDateTime = (LocalDateTime)result.Value; ZonedDateTime zonedOpDateTime = localParsedDateTime.InZoneStrictly(opTimeZone); ZonedDateTime zonedReactorDateTime = zonedOpDateTime.WithZone(reactorTimeZone); outputString = zonedReactorDateTime.LocalDateTime.ToString("g", null); } reactorTimeEmbed .AddField("Poster's Time", $"\"{parsedText}\"") .AddField("Your time", $"{outputString}"); } await reactor.SendMessageAsync(embed: reactorTimeEmbed); } catch (Exception exception) { this.Logger.Log(LogLevel.Error, exception, "Error in sending reactor the DM"); } } }); }
/// <summary> /// Converts a <see cref="DateTimeOffset"/> to <see cref="ZonedDateTime"/>. /// </summary> /// <remarks>This is a convenience method which calls <see cref="ZonedDateTime.FromDateTimeOffset"/>.</remarks> /// <param name="dateTimeOffset">The <c>DateTimeOffset</c> to convert.</param> /// <returns>A new <see cref="ZonedDateTime"/> with the same values as <paramref name="dateTimeOffset"/>, /// using a fixed-offset time zone.</returns> public static ZonedDateTime ToZonedDateTime(this DateTimeOffset dateTimeOffset) => ZonedDateTime.FromDateTimeOffset(dateTimeOffset);
private async Task SendAdjustedDate(DiscordClient c, MessageReactionAddEventArgs e) { if (e.User.IsBot) { return; } DiscordChannel channel = await c.GetChannelAsync(e.Channel.Id); _ = Task.Run(async() => { if (e.Emoji.Equals(this.clockEmoji)) { try { using IBotAccessProvider database = this.providerBuilder.Build(); DiscordMember reactor = (DiscordMember)e.User; DiscordMessage msg = await channel.GetMessageAsync(e.Message.Id); IEnumerable <DateTimeV2ModelResult> parserList = DateTimeRecognizer.RecognizeDateTime(msg.Content, culture: Culture.English) .Select(x => x.ToDateTimeV2ModelResult()).Where(x => x.TypeName is DateTimeV2Type.Time or DateTimeV2Type.DateTime); if (!parserList.Any()) { await reactor.SendMessageAsync("Hey, you're stupid, stop trying to react to messages that don't have times in them."); return; } DiscordEmbedBuilder reactorTimeEmbed = new DiscordEmbedBuilder().WithTitle("You requested a timezone conversion"); string opTimeZoneId = database.GetUsersTimeZone(msg.Author.Id)?.TimeZoneId; string reactorTimeZoneId = database.GetUsersTimeZone(e.User.Id)?.TimeZoneId; if (opTimeZoneId is null) { await reactor.SendMessageAsync("The original poster has not set up a time zone yet."); return; } if (reactorTimeZoneId is null) { await channel.SendMessageAsync("You have not set up a time zone yet. Use `time init` to set up your time zone."); return; } DateTimeZone opTimeZone = this.timeZoneProvider.GetZoneOrNull(opTimeZoneId); DateTimeZone reactorTimeZone = this.timeZoneProvider.GetZoneOrNull(reactorTimeZoneId); if (opTimeZone == null || reactorTimeZone == null) { await reactor.SendMessageAsync("There was a problem, please reach out to your bot developer."); return; } IEnumerable <(string, DateTimeV2Value)> results = parserList.SelectMany(x => x.Values.Select(y => (x.Text, y))); foreach ((string parsedText, DateTimeV2Value result) in results) { string outputString; if (result.Type is DateTimeV2Type.Time) { DateTimeOffset messageDateTime = msg.Timestamp; ZonedDateTime zonedMessageDateTime = ZonedDateTime.FromDateTimeOffset(messageDateTime); LocalTime localParsedTime = (LocalTime)result.Value; LocalDateTime localParsedDateTime = localParsedTime.On(zonedMessageDateTime.LocalDateTime.Date); ZonedDateTime zonedOpDateTime = localParsedDateTime.InZoneStrictly(opTimeZone); ZonedDateTime zonedReactorDateTime = zonedOpDateTime.WithZone(reactorTimeZone); outputString = zonedReactorDateTime.LocalDateTime.TimeOfDay.ToString("t", null); } else { LocalDateTime localParsedDateTime = (LocalDateTime)result.Value; ZonedDateTime zonedOpDateTime = localParsedDateTime.InZoneStrictly(opTimeZone); ZonedDateTime zonedReactorDateTime = zonedOpDateTime.WithZone(reactorTimeZone); outputString = zonedReactorDateTime.LocalDateTime.ToString("g", null); } reactorTimeEmbed .AddField("Poster's Time", $"\"{parsedText}\"") .AddField("Your time", $"{outputString}"); } await reactor.SendMessageAsync(embed: reactorTimeEmbed); } catch (Exception exception) { this.logger.Log(LogLevel.Error, exception, "Error in sending reactor the DM"); } } }); }
DynamoDBEntry CreateZonedEntry() { var val = ZonedDateTime.FromDateTimeOffset(DateTimeOffset.Now); return(converter.ToEntry(val)); }
void ITableEntity.ReadEntity(IDictionary <string, EntityProperty> properties, OperationContext operationContext) { var getter = getPropertyGetter(GetType()); _binder.Populate(this, properties .Select(x => { var value = x.Value.PropertyAsObject?.ToString(); if (x.Value.PropertyType != EdmType.DateTime) { return(new KeyValuePair <string, string>(x.Key, value)); } if (x.Value.DateTimeOffsetValue.HasValue) { if (TryGetPropertyType(getter, GetType(), x.Key, out var propertyType)) { if (propertyType == typeof(Instant)) { value = InstantPattern.ExtendedIso.Format( Instant.FromDateTimeOffset(x.Value.DateTimeOffsetValue.Value)); } else if (propertyType == typeof(OffsetDateTime)) { value = OffsetDateTimePattern.Rfc3339.Format( OffsetDateTime.FromDateTimeOffset(x.Value.DateTimeOffsetValue.Value)); } else if (propertyType == typeof(ZonedDateTime)) { value = CustomNodaConverters.ZonedDateTimeFormatter.Format( ZonedDateTime.FromDateTimeOffset(x.Value.DateTimeOffsetValue.Value)); } else if (propertyType == typeof(LocalDateTime)) { value = LocalDateTimePattern.ExtendedIso.Format( LocalDateTime.FromDateTime(x.Value.DateTimeOffsetValue.Value.DateTime)); } else if (propertyType == typeof(LocalDate)) { value = LocalDatePattern.Iso.Format( LocalDate.FromDateTime(x.Value.DateTimeOffsetValue.Value.DateTime)); } else { value = x.Value.DateTimeOffsetValue.Value.ToString("O"); } } else { value = x.Value.DateTimeOffsetValue.Value.ToString("O"); } } if (x.Value.DateTime.HasValue) { if (TryGetPropertyType(getter, GetType(), x.Key, out var propertyType)) { if (propertyType == typeof(LocalDateTime)) { value = LocalDateTimePattern.ExtendedIso.Format( LocalDateTime.FromDateTime(x.Value.DateTime.Value)); } else if (propertyType == typeof(LocalDate)) { value = LocalDatePattern.Iso.Format(LocalDate.FromDateTime(x.Value.DateTime.Value)); } else { value = x.Value.DateTime.Value.ToString("O"); } } else { value = x.Value.DateTime.Value.ToString("O"); } } return(new KeyValuePair <string, string>(x.Key, value)); })); }
public static ZonedDateTime ParseIsoTime(string isoTimeString) { return(ZonedDateTime.FromDateTimeOffset(DateTimeOffset.Parse(isoTimeString, CultureInfo.InvariantCulture))); }
public Task <object> GetPropertyValueAsync <TElement>(PropertyInfo property, TElement element, ResolvingContext context) where TElement : IContentElementValue <DateTime> { var udt = DateTime.SpecifyKind(element.Value, DateTimeKind.Utc); return(Task.FromResult((object)ZonedDateTime.FromDateTimeOffset(udt))); }