Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added UseLocalTime option so we're not always stuck with UTC #5

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/Examples/AspNetCoreHost/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void Configure(IApplicationBuilder app)
{
app.UseQuartzmin(new QuartzminOptions()
{
UseLocalTime = true,
Scheduler = DemoScheduler.Create().Result,
});
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Examples/NetCoreSelfHost/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

<add key="quartz.plugin.quartzmin.type" value="Quartzmin.SelfHost.QuartzminPlugin, Quartzmin.SelfHost" />
<add key="quartz.plugin.quartzmin.url" value="http://*:333" />
<add key="quartz.plugin.quartzmin.useLocalTime" value="true" />
<add key="quartz.plugin.quartzmin.defaultDateFormat" value="dd/MM/yyyy" />
</quartz>
</configuration>
2 changes: 2 additions & 0 deletions Source/Examples/WinFormSelfHost/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

<add key="quartz.plugin.quartzmin.type" value="Quartzmin.SelfHost.QuartzminPlugin, Quartzmin.SelfHost" />
<add key="quartz.plugin.quartzmin.url" value="http://localhost:9999" />
<add key="quartz.plugin.quartzmin.useLocalTime" value="true" />
<add key="quartz.plugin.quartzmin.defaultDateFormat" value="dd/MM/yyyy" />
</quartz>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
Expand Down
8 changes: 4 additions & 4 deletions Source/Quartz.Plugins.RecentHistory/ExecutionHistoryPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ExecutionHistoryPlugin : ISchedulerPlugin, IJobListener
return Task.FromResult(0);
}

public async Task Start(CancellationToken cancellationToken = default(CancellationToken))
public Task Start(CancellationToken cancellationToken = default(CancellationToken))
{
_store = _scheduler.Context.GetExecutionHistoryStore();

Expand All @@ -40,15 +40,15 @@ public class ExecutionHistoryPlugin : ISchedulerPlugin, IJobListener

_store.SchedulerName = _scheduler.SchedulerName;

await _store.Purge();
return _store.Purge();
}

public Task Shutdown(CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(0);
}

public async Task JobToBeExecuted(IJobExecutionContext context, CancellationToken cancellationToken = default(CancellationToken))
public Task JobToBeExecuted(IJobExecutionContext context, CancellationToken cancellationToken = default(CancellationToken))
{
var entry = new ExecutionHistoryEntry()
{
Expand All @@ -61,7 +61,7 @@ public class ExecutionHistoryPlugin : ISchedulerPlugin, IJobListener
Job = context.JobDetail.Key.ToString(),
Trigger = context.Trigger.Key.ToString(),
};
await _store.Save(entry);
return _store.Save(entry);
}

public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default(CancellationToken))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public Task<ExecutionHistoryEntry> Get(string fireInstanceId)
{
if (_data.TryGetValue(fireInstanceId, out var entry))
return Task.FromResult(entry);
else
return Task.FromResult<ExecutionHistoryEntry>(null); ;
return Task.FromResult<ExecutionHistoryEntry>(null);

}
}

Expand Down
9 changes: 7 additions & 2 deletions Source/Quartzmin.SelfHost/QuartzminPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class QuartzminPlugin : ISchedulerPlugin
public string DefaultDateFormat { get; set; }
public string DefaultTimeFormat { get; set; }

public bool UseLocalTime { get; set; }

public string Logo { get; set; }
public string ProductName { get; set; }

Expand All @@ -31,7 +33,7 @@ public class QuartzminPlugin : ISchedulerPlugin
}

#if NETSTANDARD
public async Task Start(CancellationToken cancellationToken = default(CancellationToken))
public Task Start(CancellationToken cancellationToken = default(CancellationToken))
{
var host = Microsoft.AspNetCore.WebHost.CreateDefaultBuilder().Configure(app => {
app.UseQuartzmin(CreateQuartzminOptions());
Expand All @@ -46,7 +48,7 @@ public class QuartzminPlugin : ISchedulerPlugin

_webApp = host;

await host.StartAsync();
return host.StartAsync();
}
#endif

Expand Down Expand Up @@ -81,6 +83,9 @@ private QuartzminOptions CreateQuartzminOptions()
if (!string.IsNullOrEmpty(ProductName))
options.ProductName = ProductName;

if (UseLocalTime)
options.UseLocalTime = UseLocalTime;

return options;
}

Expand Down
1 change: 1 addition & 0 deletions Source/Quartzmin/Controllers/SchedulerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public async Task<IActionResult> Index()
History = histogram,
MetaData = metadata,
RunningSince = metadata.RunningSince?.UtcDateTime.ToDefaultFormat() ?? "N / A",
UtcLabel = DateTimeSettings.UseLocalTime ? string.Empty : "UTC",
Environment.MachineName,
Application = Environment.CommandLine,
JobsCount = jobKeys.Count,
Expand Down
1 change: 1 addition & 0 deletions Source/Quartzmin/DateTimeSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ internal static class DateTimeSettings
{
public static string DefaultDateFormat { get; set; } = "MM/dd/yyyy";
public static string DefaultTimeFormat { get; set; } = "HH:mm:ss";
public static bool UseLocalTime { get; set; } = false;
}
}
7 changes: 6 additions & 1 deletion Source/Quartzmin/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public static JobDataMapItemBase[] GetModel(this IEnumerable<Dictionary<string,

public static string ToDefaultFormat(this DateTime date)
{
return date.ToString(DateTimeSettings.DefaultDateFormat + " " + DateTimeSettings.DefaultTimeFormat, CultureInfo.InvariantCulture);
return DateTimeSettings.UseLocalTime
? date.ToLocalTime()
.ToString(DateTimeSettings.DefaultDateFormat + " " + DateTimeSettings.DefaultTimeFormat,
CultureInfo.InvariantCulture)
: date.ToString(DateTimeSettings.DefaultDateFormat + " " + DateTimeSettings.DefaultTimeFormat,
CultureInfo.InvariantCulture);
}

public static Dictionary<string, string> ToDictionary(this IEnumerable<TimeZoneInfo> timeZoneInfos)
Expand Down
7 changes: 7 additions & 0 deletions Source/Quartzmin/QuartzminOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public string DefaultTimeFormat
set => DateTimeSettings.DefaultTimeFormat = value;
}

public bool UseLocalTime
{
get => DateTimeSettings.UseLocalTime;
set => DateTimeSettings.UseLocalTime = value;
}

public QuartzminOptions()
{
DefaultSelectedType = new StringHandler() { Name = "String" };
Expand All @@ -70,6 +76,7 @@ public QuartzminOptions()
string.IsNullOrEmpty(SitePhysicalDirectory) ? null : Path.Combine(SitePhysicalDirectory, "Content");
internal string ViewsRootDirectory =>
string.IsNullOrEmpty(SitePhysicalDirectory) ? null : Path.Combine(SitePhysicalDirectory, "Views");

#else
internal string ContentRootDirectory => null;
internal string ViewsRootDirectory => null;
Expand Down
2 changes: 1 addition & 1 deletion Source/Quartzmin/Views/Scheduler/Index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</tr>
<tr>
<td>Running Since</td>
<td>{{RunningSince}} UTC</td>
<td>{{RunningSince}} {{UtcLabel}}</td>
</tr>
<tr>
<td>Shutdown</td>
Expand Down