public ActionResult GetTimeZones() { var res = TimeZoneUtils.GetAvailableTimeZones() .Select(tz => new { name = tz, value = tz }).OrderBy(m => m.name); return(this.JsonSuccess(data: res, message: null)); }
public ActionResult GetDateFormats() { var res = TimeZoneUtils.GetAvailableDateFormat() .Select(df => new { name = df, value = df }); return(JsonSuccess(data: res, message: null)); }
public EngineConfig() { Uuid = Guid.NewGuid().ToString(); HomeDirectory = "./argon"; Logger = new LoggerConfig(); UseSwagger = true; SecretKey = RandomStringUtils.RandomString(32); TimeZone = TimeZoneUtils.ToTzdb(TimeZoneInfo.Local); UnitSystem = "metric"; Language = CultureInfo.CurrentCulture.TwoLetterISOLanguageName; }
public void SetTimeZone(Guid userId, string timeZoneId) { if (!TimeZoneUtils.GetAvailableTimeZones().Contains(timeZoneId, StringComparer.InvariantCultureIgnoreCase)) { throw new ArgumentException($"TimeZone \"{timeZoneId}\" is not registered."); } var user = this.GetUserById(userId); user.TzdbTimeZoneId = timeZoneId; this.UpdateUser(user); }
public void TestGetTzIdFromWindowsId() { string id; bool result; result = TimeZoneUtils.TryGetTzIdFromWindowsId("Tokyo Standard Time", out id); Assert.IsTrue(result); Assert.AreEqual("Asia/Tokyo", id); result = TimeZoneUtils.TryGetTzIdFromWindowsId("Pacific Standard Time", out id); Assert.IsTrue(result); Assert.AreEqual("America/Los_Angeles", id); result = TimeZoneUtils.TryGetTzIdFromWindowsId("Dateline Standard Time", out id); Assert.IsTrue(result); Assert.AreEqual("Etc/GMT+12", id); result = TimeZoneUtils.TryGetTzIdFromWindowsId("Line Islands Standard Time", out id); Assert.IsTrue(result); Assert.AreEqual("Pacific/Kiritimati", id); result = TimeZoneUtils.TryGetTzIdFromWindowsId("Tokyo Standard Time", out id, TimeZoneUtils.PreferredTzId.TerritoryIndipendent); Assert.IsTrue(result); Assert.AreEqual("Etc/GMT-9", id); result = TimeZoneUtils.TryGetTzIdFromWindowsId("Pacific Standard Time", out id, TimeZoneUtils.PreferredTzId.TerritoryIndipendent); Assert.IsTrue(result); Assert.AreEqual("PST8PDT", id); result = TimeZoneUtils.TryGetTzIdFromWindowsId("GMT Standard Time", out id, TimeZoneUtils.PreferredTzId.TerritoryIndipendent); Assert.IsTrue(result); Assert.AreEqual("Europe/London", id); result = TimeZoneUtils.TryGetTzIdFromWindowsId("No Existence Time Zone Id", out id, TimeZoneUtils.PreferredTzId.TerritoryIndipendent); Assert.IsFalse(result); Assert.IsNull(id); id = TimeZoneUtils.GetTzIdFromWindowsId("Tokyo Standard Time"); Assert.AreEqual("Asia/Tokyo", id); var ex = Assert.ThrowsException <TimeZoneInfoNotFoundException>(() => { id = TimeZoneUtils.GetTzIdFromWindowsId("No Existence Time Zone Id"); }); Assert.AreEqual("TimeZone id 'No Existence Time Zone Id' is not found.", ex.Message); }
public void TestGetWindowsIdFromTzId() { string id; bool result; result = TimeZoneUtils.TryGetWindowsIdFromTzId("Asia/Tokyo", out id); Assert.IsTrue(result); Assert.AreEqual("Tokyo Standard Time", id); result = TimeZoneUtils.TryGetWindowsIdFromTzId("America/Los_Angeles", out id); Assert.IsTrue(result); Assert.AreEqual("Pacific Standard Time", id); result = TimeZoneUtils.TryGetWindowsIdFromTzId("Etc/GMT+12", out id); Assert.IsTrue(result); Assert.AreEqual("Dateline Standard Time", id); result = TimeZoneUtils.TryGetWindowsIdFromTzId("Etc/GMT-14", out id); Assert.IsTrue(result); Assert.AreEqual("Line Islands Standard Time", id); result = TimeZoneUtils.TryGetWindowsIdFromTzId("NoExistence/TimeZoneId", out id); Assert.IsFalse(result); Assert.IsNull(id); id = TimeZoneUtils.GetWindowsIdFromTzId("Asia/Tokyo"); Assert.AreEqual("Tokyo Standard Time", id); var ex = Assert.ThrowsException <TimeZoneInfoNotFoundException>(() => { id = TimeZoneUtils.GetWindowsIdFromTzId("NoExistence/TimeZoneId"); }); Assert.AreEqual("TimeZone id 'NoExistence/TimeZoneId' is not found.", ex.Message); }
public void TestGetTzIdsFromWindowsId() { string[] ids; bool result; result = TimeZoneUtils.TryGetTzIdsFromWindowsId("UTC", out ids); Assert.IsTrue(result); // it may change in the future. Assert.AreEqual(3, ids.Length); Assert.IsTrue(ids.Contains("Etc/GMT")); Assert.IsTrue(ids.Contains("America/Danmarkshavn")); Assert.IsTrue(ids.Contains("Etc/UTC")); result = TimeZoneUtils.TryGetTzIdsFromWindowsId("No Existence Time Zone Id", out ids); Assert.IsFalse(result); Assert.IsNull(ids); ids = TimeZoneUtils.GetTzIdsFromWindowsId("UTC"); Assert.IsNotNull(ids); // it may change in the future. Assert.AreEqual(3, ids.Length); Assert.IsTrue(ids.Contains("Etc/GMT")); Assert.IsTrue(ids.Contains("America/Danmarkshavn")); Assert.IsTrue(ids.Contains("Etc/UTC")); var ex = Assert.ThrowsException <TimeZoneInfoNotFoundException>(() => { ids = TimeZoneUtils.GetTzIdsFromWindowsId("No Existence Time Zone Id"); }); Assert.AreEqual("TimeZone id 'No Existence Time Zone Id' is not found.", ex.Message); }
public void TestGetDateTimeOffsets() { DateTime dateTime; DateTimeOffset[] dateTimeOffsetResult; TimeZoneInfo timeZoneInfo; timeZoneInfo = TimeZoneUtils.GetTimeZoneInfoFromTzId("Asia/Tokyo"); dateTime = new DateTime(2021, 01, 01, 00, 00, 00); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(1, dateTimeOffsetResult.Length); Assert.AreEqual("2021-01-01T00:00:00.000+09:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 01, 01, 00, 00, 00, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(1, dateTimeOffsetResult.Length); Assert.AreEqual("2021-01-01T09:00:00.000+09:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); timeZoneInfo = TimeZoneUtils.GetTimeZoneInfoFromTzId("America/Los_Angeles"); dateTime = new DateTime(2021, 01, 01, 00, 00, 00); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(1, dateTimeOffsetResult.Length); Assert.AreEqual("2021-01-01T00:00:00.000-08:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 03, 14, 01, 59, 59); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(1, dateTimeOffsetResult.Length); Assert.AreEqual("2021-03-14T01:59:59.000-08:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 03, 14, 02, 00, 00); Assert.ThrowsException <ArgumentException>(() => { dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); }); dateTime = new DateTime(2021, 11, 07, 00, 59, 59); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(1, dateTimeOffsetResult.Length); Assert.AreEqual("2021-11-07T00:59:59.000-07:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 01, 59, 59); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(2, dateTimeOffsetResult.Length); Assert.AreEqual("2021-11-07T01:59:59.000-08:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); Assert.AreEqual("2021-11-07T01:59:59.000-07:00", dateTimeOffsetResult[1].ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 02, 00, 00); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(1, dateTimeOffsetResult.Length); Assert.AreEqual("2021-11-07T02:00:00.000-08:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 08, 00, 00, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(1, dateTimeOffsetResult.Length); Assert.AreEqual("2021-11-07T01:00:00.000-07:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 08, 59, 59, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(1, dateTimeOffsetResult.Length); Assert.AreEqual("2021-11-07T01:59:59.000-07:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 09, 00, 00, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, timeZoneInfo); Assert.AreEqual(1, dateTimeOffsetResult.Length); Assert.AreEqual("2021-11-07T01:00:00.000-08:00", dateTimeOffsetResult[0].ToString(DATE_TIME_FORMATE)); Assert.ThrowsException <ArgumentNullException>(() => { dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffsets(dateTime, null); }); }
public void TestGetDateTimeOffset() { DateTime dateTime; DateTimeOffset dateTimeOffset; DateTimeOffset dateTimeOffsetResult; TimeZoneInfo timeZoneInfo; timeZoneInfo = TimeZoneUtils.GetTimeZoneInfoFromTzId("Asia/Tokyo"); dateTime = new DateTime(2021, 01, 01, 00, 00, 00); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-01-01T00:00:00.000+09:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 01, 01, 00, 00, 00, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-01-01T09:00:00.000+09:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 01, 01, 00, 00, 00, TimeSpan.FromHours(9.0f)); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-01-01T00:00:00.000+09:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 01, 01, 00, 00, 00, TimeSpan.Zero); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-01-01T09:00:00.000+09:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 01, 01, 00, 00, 00, TimeSpan.FromHours(1.0f)); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-01-01T08:00:00.000+09:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); timeZoneInfo = TimeZoneInfo.Utc; dateTime = new DateTime(2021, 01, 01, 00, 00, 00); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-01-01T00:00:00.000+00:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 01, 01, 00, 00, 00, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-01-01T00:00:00.000+00:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); timeZoneInfo = TimeZoneUtils.GetTimeZoneInfoFromTzId("America/Los_Angeles"); dateTime = new DateTime(2021, 01, 01, 00, 00, 00); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-01-01T00:00:00.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 03, 14, 01, 59, 59); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-03-14T01:59:59.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 03, 14, 02, 00, 00); Assert.ThrowsException <ArgumentException>(() => { dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); }); dateTime = new DateTime(2021, 03, 14, 03, 00, 00); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-03-14T03:00:00.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 03, 14, 09, 59, 59, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-03-14T01:59:59.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 03, 14, 10, 00, 00, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-03-14T03:00:00.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 03, 14, 09, 59, 59, TimeSpan.Zero); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-03-14T01:59:59.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 03, 14, 10, 00, 00, TimeSpan.Zero); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-03-14T03:00:00.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 03, 14, 01, 59, 59, TimeSpan.FromHours(-8.0f)); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-03-14T01:59:59.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 03, 14, 03, 00, 00, TimeSpan.FromHours(-7.0f)); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-03-14T03:00:00.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 00, 59, 59); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-11-07T00:59:59.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 01, 59, 59); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-11-07T01:59:59.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 02, 00, 00); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-11-07T02:00:00.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 07, 59, 59, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-11-07T00:59:59.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 08, 00, 00, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-11-07T01:00:00.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 08, 59, 59, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-11-07T01:59:59.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTime = new DateTime(2021, 11, 07, 09, 00, 00, DateTimeKind.Utc); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, timeZoneInfo); Assert.AreEqual("2021-11-07T01:00:00.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 11, 07, 08, 59, 59, TimeSpan.Zero); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-11-07T01:59:59.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 11, 07, 09, 00, 00, TimeSpan.Zero); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-11-07T01:00:00.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 11, 07, 01, 59, 59, TimeSpan.FromHours(-7.0f)); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-11-07T01:59:59.000-07:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); dateTimeOffset = new DateTimeOffset(2021, 11, 07, 01, 00, 00, TimeSpan.FromHours(-8.0f)); dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, timeZoneInfo); Assert.AreEqual("2021-11-07T01:00:00.000-08:00", dateTimeOffsetResult.ToString(DATE_TIME_FORMATE)); Assert.ThrowsException <ArgumentNullException>(() => { dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTime, null); }); Assert.ThrowsException <ArgumentNullException>(() => { dateTimeOffsetResult = TimeZoneUtils.GetDateTimeOffset(dateTimeOffset, null); }); }
public void TestGetTimeZoneInfoAndGetIdFromTimeZoneInfo() { TimeZoneInfo timeZoneInfo; bool result; string id; result = TimeZoneUtils.TryGetTimeZoneInfoFromTzId("Asia/Tokyo", out timeZoneInfo); Assert.IsTrue(result); Assert.IsNotNull(timeZoneInfo); result = TimeZoneUtils.TryGetTzIdFromTimeZoneInfo(timeZoneInfo, out id); Assert.IsTrue(result); Assert.AreEqual("Asia/Tokyo", id); result = TimeZoneUtils.TryGetWindowsIdFromTimeZoneInfo(timeZoneInfo, out id); Assert.IsTrue(result); Assert.AreEqual("Tokyo Standard Time", id); result = TimeZoneUtils.TryGetTimeZoneInfoFromWindowsId("Tokyo Standard Time", out timeZoneInfo); Assert.IsTrue(result); Assert.IsNotNull(timeZoneInfo); result = TimeZoneUtils.TryGetTzIdFromTimeZoneInfo(timeZoneInfo, out id); Assert.IsTrue(result); Assert.AreEqual("Asia/Tokyo", id); result = TimeZoneUtils.TryGetTimeZoneInfoFromTzId("NoExistence/TimeZoneId", out timeZoneInfo); Assert.IsFalse(result); Assert.IsNull(timeZoneInfo); result = TimeZoneUtils.TryGetTimeZoneInfoFromWindowsId("No Existence Time Zone Id", out timeZoneInfo); Assert.IsFalse(result); Assert.IsNull(timeZoneInfo); timeZoneInfo = TimeZoneUtils.GetTimeZoneInfoFromTzId("Asia/Tokyo"); Assert.IsNotNull(timeZoneInfo); id = TimeZoneUtils.GetTzIdFromTimeZoneInfo(timeZoneInfo); Assert.AreEqual("Asia/Tokyo", id); id = TimeZoneUtils.GetWindowsIdFromTimeZoneInfo(timeZoneInfo); Assert.AreEqual("Tokyo Standard Time", id); var ex = Assert.ThrowsException <TimeZoneInfoNotFoundException>(() => { timeZoneInfo = TimeZoneUtils.GetTimeZoneInfoFromTzId("NoExistence/TimeZoneId"); }); Assert.AreEqual("TimeZoneInfo for id 'NoExistence/TimeZoneId' is not found.", ex.Message); ex = Assert.ThrowsException <TimeZoneInfoNotFoundException>(() => { timeZoneInfo = TimeZoneUtils.GetTimeZoneInfoFromWindowsId("No Existence Time Zone Id"); }); Assert.AreEqual("TimeZoneInfo for id 'No Existence Time Zone Id' is not found.", ex.Message); timeZoneInfo = TimeZoneInfo.CreateCustomTimeZone("Asia/Tokyo", TimeSpan.FromHours(9.0f), "Tokyo", "Tokyo"); result = TimeZoneUtils.TryGetTzIdFromTimeZoneInfo(timeZoneInfo, out id); Assert.IsTrue(result); Assert.AreEqual("Asia/Tokyo", id); result = TimeZoneUtils.TryGetWindowsIdFromTimeZoneInfo(timeZoneInfo, out id); Assert.IsTrue(result); Assert.AreEqual("Tokyo Standard Time", id); timeZoneInfo = TimeZoneInfo.CreateCustomTimeZone("NoExistenceTimeZone", TimeSpan.FromHours(1.0f), "No Existence", "No Existence"); result = TimeZoneUtils.TryGetTzIdFromTimeZoneInfo(timeZoneInfo, out id); Assert.IsFalse(result); Assert.IsNull(id); result = TimeZoneUtils.TryGetWindowsIdFromTimeZoneInfo(timeZoneInfo, out id); Assert.IsFalse(result); Assert.IsNull(id); ex = Assert.ThrowsException <TimeZoneInfoNotFoundException>(() => { id = TimeZoneUtils.GetTzIdFromTimeZoneInfo(timeZoneInfo); }); Assert.AreEqual("TimeZone id 'NoExistenceTimeZone' is not found.", ex.Message); ex = Assert.ThrowsException <TimeZoneInfoNotFoundException>(() => { id = TimeZoneUtils.GetWindowsIdFromTimeZoneInfo(timeZoneInfo); }); Assert.AreEqual("TimeZone id 'NoExistenceTimeZone' is not found.", ex.Message); }
/// <inheritdoc cref="IAzureTablesService.QueryDataAsync(string, DateTime, DateTime, QboxQueryResolution, bool)"/> public async Task <QboxPagedDataQueryResult <QboxCounterData> > QueryDataAsync(string serialNumber, DateTime from, DateTime to, QboxQueryResolution resolution, bool adjustHours) { Guard.NotNullOrEmpty(serialNumber, nameof(serialNumber)); int adjustedHours = 0; DateTime fromQueryParameter = from; if (adjustHours) { fromQueryParameter = from.AddDays(-1); adjustedHours = TimeZoneUtils.GetHoursDifferenceFromUTC(from); } string fromPartitionKey = PartitionKeyHelper.Construct(serialNumber, fromQueryParameter); string toPartitionKey = PartitionKeyHelper.Construct(serialNumber, to); string fromRowKey = DateTimeRowKeyHelper.Construct(fromQueryParameter); string toRowKey = DateTimeRowKeyHelper.Construct(to); _logger.LogInformation("Querying Table {table} with PartitionKey {fromPartitionKey} to {toPartitionKey} and RowKey {fromRowKey} to {toRowKey} and AdjustHours = {adjustHours}", _measurementTable.Name, fromPartitionKey, toPartitionKey, fromRowKey, toRowKey, adjustHours); var queue = new ConcurrentQueue <List <MeasurementEntity> >(); var tasks = EachDay(fromQueryParameter, to).Select(async date => { var result = await _measurementTable.Set.Where(m => m.PartitionKey == PartitionKeyHelper.Construct(serialNumber, date) && string.CompareOrdinal(m.RowKey, fromRowKey) <= 0 && string.CompareOrdinal(m.RowKey, toRowKey) > 0 ).ToListAsync(); queue.Enqueue(result); }); await Task.WhenAll(tasks); var entities = queue.SelectMany(x => x) .Where(e => e.MeasureTimeAdjusted != true) // Exclude adjusted measurements here. Not possible in real query above ! .Where(e => !adjustHours || e.MeasureTime > from.AddHours(-adjustedHours)) // Filter .OrderBy(e => e.MeasureTime).ToList(); // Adjust MeasureTime if needed if (adjustHours) { foreach (var entity in entities) { entity.MeasureTime = entity.MeasureTime.AddHours(adjustedHours); } } var deltas = entities.Zip(entities.Skip(1), (current, next) => new QboxCounterData { MeasureTime = next.MeasureTime, Delta0181 = next.Counter0181 - current.Counter0181 ?? 0, Delta0182 = next.Counter0182 - current.Counter0182 ?? 0, Delta0281 = next.Counter0281 - current.Counter0281 ?? 0, Delta0282 = next.Counter0282 - current.Counter0282 ?? 0, Delta2421 = next.Counter2421 - current.Counter2421 ?? 0, }).ToList(); if (deltas.Count > 0) { deltas.Insert(0, new QboxCounterData { MeasureTime = entities[0].MeasureTime, Delta0181 = 0, Delta0182 = 0, Delta0281 = 0, Delta0282 = 0, Delta2421 = 0 }); } var groupedByTimeFrame = from delta in deltas group delta by new { MeasureTimeRounded = resolution.TruncateTime(delta.MeasureTime) } into g select new QboxCounterData { LabelText = resolution.GetLabelText(g.Key.MeasureTimeRounded), LabelValue = resolution.GetLabelValue(g.Key.MeasureTimeRounded), MeasureTime = g.Key.MeasureTimeRounded, Delta0181 = g.Sum(x => x.Delta0181), Delta0182 = g.Sum(x => x.Delta0182), Delta0281 = g.Sum(x => x.Delta0281) * -1, Delta0282 = g.Sum(x => x.Delta0282) * -1, Delta2421 = g.Sum(x => x.Delta2421) }; var itemsFound = groupedByTimeFrame.ToList(); var items = FillGaps(from, to, resolution, itemsFound); var overview = new QboxCounterData { LabelText = "overview", MeasureTime = DateTime.UtcNow, Delta0181 = entities.Max(e => e.Counter0181) - entities.Min(e => e.Counter0181) ?? 0, Delta0182 = entities.Max(e => e.Counter0182) - entities.Min(e => e.Counter0182) ?? 0, Delta0281 = (entities.Max(e => e.Counter0281) - entities.Min(e => e.Counter0281) ?? 0) * -1, Delta0282 = (entities.Max(e => e.Counter0282) - entities.Min(e => e.Counter0282) ?? 0) * -1, Delta2421 = entities.Max(e => e.Counter2421) - entities.Min(e => e.Counter2421) ?? 0 }; // Define DrillDownQuery if (resolution > QboxQueryResolution.FiveMinutes) { foreach (var item in items) { item.DrillDownQuery = GetDrillDownQboxDataQuery(item.MeasureTime, resolution, adjustHours); } } return(new QboxPagedDataQueryResult <QboxCounterData> { Overview = overview, Items = items, Count = items.Count }); }
public static void GenerateRadGridColumnsFromFieldMetadata(RadGrid rgMainDataGrid, List <FieldMetadata> columnsToDisplay) { string tz = TimeZoneUtils.GetTimeZoneAbbreviatedTime(DateTime.Now, ConciergeAPI.CurrentTimeZone); if (columnsToDisplay == null) { return; } foreach (FieldMetadata col in columnsToDisplay) { GridBoundColumn c; //if ( col.DataType == FieldDataType.Date || col.DataType == FieldDataType.DateTime ) // c= new GridDateTimeColumn(); //else c = new GridBoundColumn(); rgMainDataGrid.Columns.Add(c); // need to add this RIGHT AWAY, or properties don't persist c.DataField = col.Name; string label = col.Label; c.HeaderText = label; if (col.ColumnWidth != null) { c.HeaderStyle.Width = col.ColumnWidth.Value; } switch (col.DataType) { case FieldDataType.Date: switch (col.DisplayType) { case FieldDisplayType.MonthDayPicker: c.DataFormatString = "{0:d}"; break; case FieldDisplayType.MonthYearPicker: c.DataFormatString = "{0:MM - dd}"; break; default: c.DataFormatString = "{0:MM/dd/yyyy}"; break; } break; case FieldDataType.DateTime: c.DataFormatString = "{0} " + tz; break; case FieldDataType.Time: c.DataFormatString = "{0:t}"; break; case FieldDataType.Integer: //if ( col.Name == null || ( col.Name != "LocalID" && ! col.Name.EndsWith( ".LocalID") )) // hack, don't format IDs - MS-308 // c.DataFormatString = "{0:N0}"; break; case FieldDataType.Decimal: int precision = col.Precision == default(int) ? 2 : col.Precision; c.DataFormatString = string.Format("{{0:N{0}}}", precision); break; case FieldDataType.Money: c.DataFormatString = "{0:C}"; // for now, but we'll have to change when we go multi-currency break; } } }