Skip to content

Commit

Permalink
#9
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasnordqvist committed Feb 26, 2016
1 parent 1c4e518 commit 75c92e7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
11 changes: 6 additions & 5 deletions GoldenFox.ANTLR/GoldenFoxLanguage.g4
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ schedule: ( everyminute
)
('and' schedule)?;

everyday: 'every day' At time;
everyday: 'every day' At times;
everyminute: 'every minute' (At secondsOffset)? (between)?;
everyhour: 'every hour' (At minutesOffset)? (between)?;
everysecond: 'every second' (between)?;
everyweekday: 'every' weekday At time;
weekdays: weekday's' At time;
numberedweekday: ((numberedDay (Last)?) | Last) 'day every week' At time;
numbereddayinmonth: ((numberedDay (Last)?) | Last) 'day every month' At time;
everyweekday: 'every' weekday At times;
weekdays: weekday's' At times;
numberedweekday: ((numberedDay (Last)?) | Last) 'day every week' At times;
numbereddayinmonth: ((numberedDay (Last)?) | Last) 'day every month' At times;

secondsOffset: ((('mm:'|'hh:mm:')INT) | (INT 'seconds')) ('and' secondsOffset)?;
minutesOffset: ((('hh:')INT(':'INT)?) | (INT 'minutes')) ('and' minutesOffset)?;
between: 'between' time 'and' time;
time: (INT':'INT(':'INT)?);
times: time ('and' time)?;
weekday: ('monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday');
numberedDay: INT('st'|'nd'|'rd'|'th');

Expand Down
26 changes: 20 additions & 6 deletions GoldenFox/Internal/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public override void ExitMinutesOffset(GoldenFoxLanguageParser.MinutesOffsetCont

public override void ExitEveryday(GoldenFoxLanguageParser.EverydayContext context)
{
_stack.Push(new Day(_timestamps.Pop()));
while(_timestamps.Any())
{
_stack.Push(new Day(_timestamps.Pop()));
}
}

public override void ExitEverysecond(GoldenFoxLanguageParser.EverysecondContext context)
Expand Down Expand Up @@ -76,12 +79,18 @@ public override void ExitEveryminute(GoldenFoxLanguageParser.EveryminuteContext

public override void ExitEveryweekday(GoldenFoxLanguageParser.EveryweekdayContext context)
{
_stack.Push(new Weekday(ParseWeekDay(context.weekday()), _timestamps.Pop()));
while (_timestamps.Any())
{
_stack.Push(new Weekday(ParseWeekDay(context.weekday()), _timestamps.Pop()));
}
}

public override void ExitWeekdays(GoldenFoxLanguageParser.WeekdaysContext context)
{
_stack.Push(new Weekday(ParseWeekDay(context.weekday()), _timestamps.Pop()));
while (_timestamps.Any())
{
_stack.Push(new Weekday(ParseWeekDay(context.weekday()), _timestamps.Pop()));
}
}

public override void ExitNumberedweekday(GoldenFoxLanguageParser.NumberedweekdayContext context)
Expand All @@ -98,7 +107,10 @@ public override void ExitNumberedweekday(GoldenFoxLanguageParser.Numberedweekday
index = index % 7;
}

_stack.Push(new Weekday((DayOfWeek)index, _timestamps.Pop()));
while (_timestamps.Any())
{
_stack.Push(new Weekday((DayOfWeek)index, _timestamps.Pop()));
}
}

public override void ExitNumbereddayinmonth(GoldenFoxLanguageParser.NumbereddayinmonthContext context)
Expand All @@ -112,8 +124,10 @@ public override void ExitNumbereddayinmonth(GoldenFoxLanguageParser.Numbereddayi
index = -index + 1;
}
}

_stack.Push(new DayInMonth(index, _timestamps.Pop()));
while (_timestamps.Any())
{
_stack.Push(new DayInMonth(index, _timestamps.Pop()));
}
}

public override void ExitEveryhour(GoldenFoxLanguageParser.EveryhourContext context)
Expand Down
4 changes: 2 additions & 2 deletions GoldenFox/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
[assembly: AssemblyCopyright("Copyright © Mattias Nordqvist")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("2.0.0")]
[assembly: AssemblyFileVersion("2.0.0")]
[assembly: AssemblyVersion("2.0.1")]
[assembly: AssemblyFileVersion("2.0.1")]
[assembly: AssemblyProduct("Golden Fox")]
[assembly: AssemblyCompany("Mattias Nordqvist")]

Expand Down
8 changes: 8 additions & 0 deletions Tests/Full/ScheduleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public void EveryDayAt_ExactlyTheSameTime_atSignWorksToo()
"every day @ 06:30".From("2015-10-05 06:30:00", true).Gives("2015-10-05 06:30:00");
}

[Test]
public void EveryDayAtTwoTimes()
{
"every day @ 06:30 and 08:30".From("2015-10-05 07:30:00").Gives("2015-10-05 08:30:00");
"every day @ 06:30 and 08:30".From("2015-10-05 05:30:00").Gives("2015-10-05 06:30:00");
"every day @ 06:30 and 08:30".From("2015-10-05 15:30:00").Gives("2015-10-06 06:30:00");
}

[Test]
public void EveryDayAt_SameDayJustLater()
{
Expand Down

0 comments on commit 75c92e7

Please sign in to comment.