public CountdownEventViewModel(Event e, TimeZoneOptions timezoneOptions) { Subject = e.Subject; Start = (e.IsAllDay ?? false) ? DateTime.Parse(e.Start.DateTime) : DateTime.Parse(e.Start.DateTime).FromUtcTo(timezoneOptions); }
public void Start() { if (!_options.Running) { return; } var timeZone = new TimeZoneOptions(_options.TimeZone).ToTimeZoneInfo(); foreach (var job in _options.Jobs) { if (!job.Running) { continue; } var cron = new CronExpression(job.Cron); if (!cron.IsValid) { _loggerFactory.CreateLogger(GetType().FullName) .LogWarning($"Invalid cron expression for '{job.Name}'."); continue; } var timer = new JobInterval(cron, timeZone, async() => await RunAsync(job.Name)); _timers.Add(timer); timer.Run(); } }
public void ShouldConvertToLocalTime(string timeZone, string expected) { var timeZoneOptions = new TimeZoneOptions(timeZone); var timeZoneInfo = timeZoneOptions.ToTimeZoneInfo(); var localDateTime = TimeZoneInfo.ConvertTime(_mockUtcTime, timeZoneInfo); var iso8601Format = localDateTime.ToString("yyyy-MM-ddTHH:mm:ss"); Assert.Equal(expected, iso8601Format); }
public CountdownViewModel( IOptions <CountdownOptions> options, IOptions <TimeZoneOptions> timezoneOptions, ICalendarManager calendarManager) { _options = options.Value; _timezoneOptions = timezoneOptions.Value; _calendarManager = calendarManager; }
public EventViewModel(Event e, string backgroundColor, string textColor, TimeZoneOptions timezoneOptions) { // All day events dont need the timezone adjustment Subject = e.Subject; Start = (e.IsAllDay ?? false) ? DateTime.Parse(e.Start.DateTime) : DateTime.Parse(e.Start.DateTime).FromUtcTo(timezoneOptions); End = (e.IsAllDay ?? false) ? DateTime.Parse(e.End.DateTime) : DateTime.Parse(e.End.DateTime).FromUtcTo(timezoneOptions); AllDay = e.IsAllDay ?? false; Recurring = e.Recurrence is not null ? true : false; BackgroundColor = backgroundColor; TextColor = textColor; }
public static TimeZoneInfo FromTimeZoneOptions(this TimeZoneOptions options) { // Windows if (TryFindSystemTimeZoneById(options.WindowsTimeZoneId, out TimeZoneInfo winTimeZoneInfo)) { return(winTimeZoneInfo); } // Linux else if (TryFindSystemTimeZoneById(options.UnixTimeZoneId, out TimeZoneInfo unixTimeZoneInfo)) { return(unixTimeZoneInfo); } else { throw new TimeZoneNotFoundException(); } }
public static DateTime FromUtcTo(this DateTime dateTime, TimeZoneOptions options) { // Windows if (TryFindSystemTimeZoneById(options.WindowsTimeZoneId, out TimeZoneInfo winTimeZoneInfo)) { Debug.WriteLine($"Found time zone '{options.WindowsTimeZoneId}'"); return(TimeZoneInfo.ConvertTimeFromUtc(dateTime, winTimeZoneInfo)); } // Linux else if (TryFindSystemTimeZoneById(options.UnixTimeZoneId, out TimeZoneInfo unixTimeZoneInfo)) { Debug.WriteLine($"Found time zone '{options.UnixTimeZoneId}'"); return(TimeZoneInfo.ConvertTimeFromUtc(dateTime, unixTimeZoneInfo)); } else { throw new TimeZoneNotFoundException(); } }
public void Start() { if (!_options.Running) { return; } var timeZone = new TimeZoneOptions(_options.TimeZone).ToTimeZoneInfo(); foreach (var job in Jobs) { var config = _options.Jobs.SingleOrDefault(entry => entry.Name == job.Name); if (config == null) { var logger = _loggerFactory.CreateLogger(job.FullName); logger.LogWarning($"No job configuration matches '{job.Name}'."); continue; } if (!config.Running) { continue; } var cron = new CronExpression(config.Cron); if (!cron.IsValid) { var logger = _loggerFactory.CreateLogger(job.FullName); logger.LogWarning($"Invalid cron expression for '{job.Name}'."); continue; } var timer = new JobInterval(cron, timeZone, async() => await RunAsync(job)); _timers.Add(timer); timer.Run(); } }