From 3cbb52becf88fa6a13f7d443f02bf9a714134b15 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Wed, 21 Dec 2016 09:41:15 +0100 Subject: [PATCH] Better default output date/time format for console app --- NCrontabConsole/Program.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/NCrontabConsole/Program.cs b/NCrontabConsole/Program.cs index 4c46bf9..845a44e 100644 --- a/NCrontabConsole/Program.cs +++ b/NCrontabConsole/Program.cs @@ -46,13 +46,19 @@ static int Main(string[] args) throw new ApplicationException("Missing required arguments. You must at least supply CRONTAB-EXPRESSION START-DATE END-DATE."); var expression = argList[0].Trim(); - var start = ParseDateArgument(argList[1], "start"); - var end = ParseDateArgument(argList[2], "end"); - var format = argList.Count > 3 ? argList[3] : "f"; - var schedule = CrontabSchedule.Parse(expression, new CrontabSchedule.ParseOptions + var options = new CrontabSchedule.ParseOptions { IncludingSeconds = expression.Split(' ').Length > 5, - }); + }; + + var start = ParseDateArgument(argList[1], "start"); + var end = ParseDateArgument(argList[2], "end"); + var format = + argList.Count > 3 ? argList[3] + : options.IncludingSeconds ? "ddd, dd MMM yyyy HH:mm:ss" + : "ddd, dd MMM yyyy HH:mm"; + + var schedule = CrontabSchedule.Parse(expression, options); foreach (var occurrence in schedule.GetNextOccurrences(start, end)) Console.Out.WriteLine(occurrence.ToString(format));