public static DateTime AsUtc(this IDateTime dateTime) { if (dateTime.IsUniversalTime) { return(DateTime.SpecifyKind(dateTime.Value, DateTimeKind.Utc)); } if (!string.IsNullOrEmpty(dateTime.TZID)) { var zone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(dateTime.TZID); if (zone == null) { var mappedTzid = TimeZoneMapper.WindowsToIanaOrNull(dateTime.TZID); zone = mappedTzid != null ? DateTimeZoneProviders.Tzdb.GetZoneOrNull(mappedTzid) : BclDateTimeZone.ForSystemDefault(); } if (zone != null) { var localDateTime = LocalDateTime.FromDateTime(dateTime.Value); var zonedDateTime = zone.AtLeniently(localDateTime); var utcDateTime = zonedDateTime.ToDateTimeUtc(); return(utcDateTime); } } // fallback return(DateTime.SpecifyKind(dateTime.Value, DateTimeKind.Local).ToUniversalTime()); }
internal static UserInfo ToBean(UserInfoRow row) { if (row == null) { return(null); } var bean = new UserInfo(); bean.UserId = row.UserId; bean.Unit = (TUnitType)row.Unit; bean.Height = row.Height; bean.Weight = row.Weight; bean.Sex = (TSexType)row.Sex; bean.ZipCode = row.ZipCode; bean.CountryId = row.CountryId; if (string.IsNullOrWhiteSpace(row.TimeZoneName)) { bean.TimeZoneName = TimeZoneMapper.GetOlsonTimeZoneName(TimeZoneInfo.Local.Id); } else { bean.TimeZoneName = row.TimeZoneName; } return(bean); }
public static void ToRow(UserInfo bean, UserInfoRow row) { if (bean == null) { return; } row.UserId = bean.UserId; row.Unit = (int)bean.Unit; row.Height = bean.Height; row.Weight = bean.Weight; row.Sex = (int)bean.Sex; row.ZipCode = bean.ZipCode; row.CountryId = bean.CountryId; if (string.IsNullOrWhiteSpace(bean.TimeZoneName)) { if (string.IsNullOrWhiteSpace(row.TimeZoneName)) // only update if not present { row.TimeZoneName = TimeZoneMapper.GetOlsonTimeZoneName(TimeZoneInfo.Local.Id); } } else { row.TimeZoneName = bean.TimeZoneName; } }
public async Task <IActionResult> GetAll() { _logger.LogInformation("TimeZome GetAll"); var res = await Task.FromResult(_timeZoneService .getAll() .ConvertAll(x => TimeZoneMapper.ToShortDto(x)) ); return(Ok(res)); }
public TimeZone this[string id] { get { if (_outlookTimeZoneIdByCaseInsensitiveId.TryGetValue(id, out string outlookId)) { return(_application.TimeZones[outlookId]); } else { return(_application.TimeZones[TimeZoneMapper.IanaToWindowsOrNull(id) ?? CurrentTimeZone.ID]); } } }
public static TrainingDayViewModel TrainingDayToViewModel(TrainingDay trainingDay, UserInfo userInfo) { //convert date to user timezone var timeZoneInfo = TimeZoneMapper.GetTimeZoneByOlsonName(userInfo.TimeZoneName); if (timeZoneInfo == null) { timeZoneInfo = TimeZoneInfo.Local; } var result = new TrainingDayViewModel() { UserId = trainingDay.UserId, Year = trainingDay.Year, WeekOfYear = trainingDay.WeekOfYear, DayOfWeek = trainingDay.DayOfWeek, TrainingDayId = trainingDay.TrainingDayId, BeginHour = TimeZoneInfo.ConvertTime(trainingDay.BeginHour, timeZoneInfo), EndHour = TimeZoneInfo.ConvertTime(trainingDay.EndHour, timeZoneInfo), Unit = (int)trainingDay.Unit }; if (trainingDay.TrainingExercises != null) { foreach (var trainingExercise in trainingDay.TrainingExercises) { if (result.RegroupExerciseUnitType == null) { result.RegroupExerciseUnitType = trainingExercise.ExerciseUnitType; } else if (result.RegroupExerciseUnitType != trainingExercise.ExerciseUnitType) { result.RegroupExerciseUnitType = null; // Mixt, stop foreach break; } } } return(result); }