Skip to content

Commit

Permalink
Better default output date/time format for console app
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Dec 21, 2016
1 parent b88f36e commit 3cbb52b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions NCrontabConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 3cbb52b

Please sign in to comment.