Ejemplo n.º 1
0
        public void GetCurrent()
        {
            var        julian          = CalendarSystem.Julian;
            FakeClock  underlyingClock = new FakeClock(NodaConstants.UnixEpoch);
            ZonedClock zonedClock      = underlyingClock.InZone(SampleZone, julian);

            Assert.AreEqual(NodaConstants.UnixEpoch, zonedClock.GetCurrentInstant());
            Assert.AreEqual(new ZonedDateTime(underlyingClock.GetCurrentInstant(), SampleZone, julian),
                            zonedClock.GetCurrentZonedDateTime());
            Assert.AreEqual(new LocalDateTime(1969, 12, 19, 2, 0, julian), zonedClock.GetCurrentLocalDateTime());
            Assert.AreEqual(new LocalDateTime(1969, 12, 19, 2, 0, julian).WithOffset(Offset.FromHours(2)),
                            zonedClock.GetCurrentOffsetDateTime());
            Assert.AreEqual(new LocalDate(1969, 12, 19, julian), zonedClock.GetCurrentDate());
            Assert.AreEqual(new LocalTime(2, 0, 0), zonedClock.GetCurrentTimeOfDay());
        }
Ejemplo n.º 2
0
        public async Task <DateTimeZone> GetTimeZone(Location location, CancellationToken cancellationToken = default)
        {
            var timeZoneRequest = new TimeZoneRequest
            {
                Location  = location,
                TimeStamp = myClock.GetCurrentInstant().ToDateTimeUtc(),
                ApiKey    = myGeoCoderOptions.GoogleKey
            };
            var timeZoneResponse = await GoogleMaps.TimeZone.QueryAsync(timeZoneRequest, myTelemetryClient, cancellationToken);

            if (!timeZoneResponse.IsSuccess())
            {
                return(myClock.Zone);
            }

            if (timeZoneResponse.TimeZoneId is { } timeZoneId&&
                myDateTimeZoneProvider.GetZoneOrNull(timeZoneId) is { } dateTimeZone)
            {
                return(dateTimeZone);
            }

            return(DateTimeZone.ForOffset(Offset.FromSeconds((int)(timeZoneResponse.RawOffSet + timeZoneResponse.DstOffSet))));
        }
Ejemplo n.º 3
0
        public async Task <IDictionary <string, object> > Handle(IDictionary <string, object> status, ControllerContext context, CancellationToken cancellationToken = default)
        {
            status["now"]                  = myClock.GetCurrentZonedDateTime().ToDateTimeOffset();
            status["defaultTimeZone"]      = $"{myClock.Zone.Id}, {myClock.Zone.GetZoneInterval(myClock.GetCurrentInstant())}";
            status["assetsRoot"]           = myUrlHelper.AssetsContent("~");
            status["lastAppliedMigration"] = (await myDB.Database.GetAppliedMigrationsAsync(cancellationToken)).LastOrDefault();
            status["polls"]                = await myDB.Set <Poll>().LongCountAsync(cancellationToken);

            status["IGNs"] = await myDB.Set <Player>().Where(_ => _.Nickname != null).LongCountAsync(cancellationToken);

            status["FCs"] = await myDB.Set <Player>().Where(_ => _.FriendCode != null).LongCountAsync(cancellationToken);

            return(status);
        }