private void fillServerTime() { lock (lockObj) { lastServerTime = WebServiceUtil.Default.GetServerTime(); lastDetectedZone = tzProvider.GetSystemDefault(); if (lastServerTime != null) { lastServerTime = lastServerTime.Value.WithZone(lastDetectedZone); } else { lastServerTime = new ZonedDateTime(clock.GetCurrentInstant(), lastDetectedZone); } measureDifference(); if (timeSinceLastServerMeasurement == null) { timeSinceLastServerMeasurement = Stopwatch.StartNew(); } else { timeSinceLastServerMeasurement.Restart(); } } }
private async void SetBP_OnClick(object sender, RoutedEventArgs e) { PersonInfo personInfo = await _connection.GetPersonInfoAsync(); HealthRecordInfo recordInfo = personInfo.SelectedRecord; IThingClient thingClient = _connection.CreateThingClient(); LocalDateTime nowLocal = _clock.GetCurrentInstant().InZone(_dateTimeZoneProvider.GetSystemDefault()).LocalDateTime; await thingClient.CreateNewThingsAsync( recordInfo.Id, new List <BloodPressure> { new BloodPressure(new HealthServiceDateTime(nowLocal), 117, 70) }); OutputBlock.Text = "Created blood pressure."; }
/// <summary> /// Initializes a new instance of the <see cref="SchemaExamples"/> class. /// Creates example value by provided <see cref="DateTime"/> and <see cref="IDateTimeZoneProvider"/>. /// </summary> /// <param name="dateTimeZoneProvider">IDateTimeZoneProvider instance.</param> /// <param name="dateTimeUtc"><see cref="DateTime"/>. If not set then <see cref="DateTime.UtcNow"/> will be used.</param> /// <param name="dateTimeZone">Optional DateTimeZone name. If not set SystemDefault will be used.</param> public SchemaExamples( IDateTimeZoneProvider dateTimeZoneProvider, DateTime?dateTimeUtc = null, string?dateTimeZone = null) { DateTime dateTimeUtcValue = dateTimeUtc ?? DateTime.UtcNow; if (dateTimeUtcValue.Kind != DateTimeKind.Utc) { throw new ArgumentException("dateTimeUtc should be UTC", nameof(dateTimeUtc)); } if (dateTimeZone != null) { DateTimeZone = dateTimeZoneProvider.GetZoneOrNull(dateTimeZone) ?? dateTimeZoneProvider.GetSystemDefault(); } else { DateTimeZone = dateTimeZoneProvider.GetSystemDefault(); } Instant = Instant.FromDateTimeUtc(dateTimeUtcValue); ZonedDateTime = Instant.InZone(DateTimeZone); Interval = new Interval(Instant, Instant.PlusTicks(TimeSpan.TicksPerDay) .PlusTicks(TimeSpan.TicksPerHour) .PlusTicks(TimeSpan.TicksPerMinute) .PlusTicks(TimeSpan.TicksPerSecond) .PlusTicks(TimeSpan.TicksPerMillisecond)); DateInterval = new DateInterval(ZonedDateTime.Date, ZonedDateTime.Date.PlusDays(1)); Period = Period.Between(ZonedDateTime.LocalDateTime, Interval.End.InZone(DateTimeZone).LocalDateTime, PeriodUnits.AllUnits); OffsetDate = new OffsetDate(ZonedDateTime.Date, ZonedDateTime.Offset); OffsetTime = new OffsetTime(ZonedDateTime.TimeOfDay, ZonedDateTime.Offset); OffsetDateTime = Instant.WithOffset(ZonedDateTime.Offset); }
/// <summary> /// Creates schemas container. /// </summary> /// <returns>Initialized <see cref="Schema"/> instance.</returns> public Schemas CreateSchemas() { IDateTimeZoneProvider dateTimeZoneProvider = _settings.DateTimeZoneProvider ?? DateTimeZoneProviders.Tzdb; var dateTimeZone = dateTimeZoneProvider.GetSystemDefault(); var instant = Instant.FromDateTimeUtc(DateTime.UtcNow); var zonedDateTime = instant.InZone(dateTimeZone); var interval = new Interval(instant, instant.PlusTicks(TimeSpan.TicksPerDay) .PlusTicks(TimeSpan.TicksPerHour) .PlusTicks(TimeSpan.TicksPerMinute) .PlusTicks(TimeSpan.TicksPerSecond) .PlusTicks(TimeSpan.TicksPerMillisecond)); var dateInterval = new DateInterval(zonedDateTime.Date, zonedDateTime.Date.PlusDays(1)); Period period = Period.Between(zonedDateTime.LocalDateTime, interval.End.InZone(dateTimeZone).LocalDateTime, PeriodUnits.AllUnits); var offsetDate = new OffsetDate(zonedDateTime.Date, zonedDateTime.Offset); var offsetTime = new OffsetTime(zonedDateTime.TimeOfDay, zonedDateTime.Offset); // https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14 return(new Schemas { Instant = () => StringSchema(instant, "date-time"), LocalDate = () => StringSchema(zonedDateTime.Date, "full-date"), LocalTime = () => StringSchema(zonedDateTime.TimeOfDay, "partial-time"), LocalDateTime = () => StringSchema(zonedDateTime.LocalDateTime), OffsetDateTime = () => StringSchema(instant.WithOffset(zonedDateTime.Offset), "date-time"), ZonedDateTime = () => StringSchema(zonedDateTime), Interval = () => new OpenApiSchema { Type = "object", Properties = new Dictionary <string, OpenApiSchema> { { ResolvePropertyName(nameof(Interval.Start)), StringSchema(interval.Start, "date-time") }, { ResolvePropertyName(nameof(Interval.End)), StringSchema(interval.End, "date-time") }, }, }, DateInterval = () => new OpenApiSchema { Type = "object", Properties = new Dictionary <string, OpenApiSchema> { { ResolvePropertyName(nameof(DateInterval.Start)), StringSchema(dateInterval.Start, "full-date") }, { ResolvePropertyName(nameof(DateInterval.End)), StringSchema(dateInterval.End, "full-date") }, }, }, Offset = () => StringSchema(zonedDateTime.Offset, "time-numoffset"), Period = () => StringSchema(period), Duration = () => StringSchema(interval.Duration), OffsetDate = () => StringSchema(offsetDate), OffsetTime = () => StringSchema(offsetTime), DateTimeZone = () => StringSchema(dateTimeZone), }); }
public DateTimeZone GetSystemDefault() { return(_provider.GetSystemDefault()); }
private TestClock[] getTestClocks(IDateTimeZoneProvider provider) { TestClock[] clocks = new TestClock[] { new TestClock("2019-02-28T00:00:00", provider.GetSystemDefault()), new TestClock("2019-02-28T23:59:59", provider.GetSystemDefault()), new TestClock("2019-02-28T12:25:30", provider.GetSystemDefault()), new TestClock("2019-02-28T22:00:00", provider.GetSystemDefault()), new TestClock("2019-03-01T05:00:00", provider.GetSystemDefault()), new TestClock("2019-03-01T08:14:59", provider.GetSystemDefault()), new TestClock("2019-03-01T08:15:00", provider.GetSystemDefault()), new TestClock("2019-03-01T13:00:00", provider.GetSystemDefault()), new TestClock("2019-03-01T19:00:00", provider.GetSystemDefault()), new TestClock("2019-03-02T05:00:00", provider.GetSystemDefault()), new TestClock("2019-03-02T08:14:59", provider.GetSystemDefault()), new TestClock("2019-03-02T08:15:00", provider.GetSystemDefault()), new TestClock("2019-03-02T13:00:00", provider.GetSystemDefault()), new TestClock("2019-03-02T19:00:00", provider.GetSystemDefault()), new TestClock("2019-03-03T01:23:00", provider.GetSystemDefault()), // For 2019, 03-03 is daylight saving time. new TestClock("2019-03-03T08:14:59", provider.GetSystemDefault()), new TestClock("2019-03-03T08:15:00", provider.GetSystemDefault()), new TestClock("2019-03-03T13:00:00", provider.GetSystemDefault()), new TestClock("2019-03-03T19:00:00", provider.GetSystemDefault()), new TestClock("2019-03-04T05:00:00", provider.GetSystemDefault()), new TestClock("2019-03-04T08:14:59", provider.GetSystemDefault()), new TestClock("2019-03-04T08:15:00", provider.GetSystemDefault()), new TestClock("2019-03-04T13:00:00", provider.GetSystemDefault()), new TestClock("2019-03-04T19:00:00", provider.GetSystemDefault()), new TestClock("2019-03-05T05:00:00", provider.GetSystemDefault()), new TestClock("2019-03-05T08:14:59", provider.GetSystemDefault()), new TestClock("2019-03-05T08:15:00", provider.GetSystemDefault()), new TestClock("2019-03-05T13:00:00", provider.GetSystemDefault()), new TestClock("2019-03-05T19:00:00", provider.GetSystemDefault()), new TestClock("2019-03-06T05:00:00", provider.GetSystemDefault()), new TestClock("2019-03-06T08:14:59", provider.GetSystemDefault()), new TestClock("2019-03-06T08:15:00", provider.GetSystemDefault()), new TestClock("2019-03-06T13:00:00", provider.GetSystemDefault()), new TestClock("2019-03-31T19:00:00", provider.GetSystemDefault()), }; return(clocks); }