Skip to content

Commit

Permalink
Allow backwards compatible parsing of BYTIME rules
Browse files Browse the repository at this point in the history
  • Loading branch information
doughsay committed Feb 20, 2018
1 parent bae378d commit 24c7b47
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased][]

## [0.8.1][] - 2018-02-17
### Fixed
- Allow backwards compatible parsing of BYTIME rule for existing schedules generated using cocktail pre-0.8.

## [0.8.0][] - 2018-02-17
### Breaking
- The `BYTIME` option of `RRULE`s in the iCalendar output is now `X-BYTIME` to better follow the standard's extensions policy
Expand Down Expand Up @@ -73,7 +77,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## 0.0.1 - 2017-09-08
### Initial release

[Unreleased]: https://github.com/peek-travel/cocktail/compare/0.8.0...HEAD
[Unreleased]: https://github.com/peek-travel/cocktail/compare/0.8.1...HEAD
[0.8.1]: https://github.com/peek-travel/cocktail/compare/0.8.0...0.8.1
[0.8.0]: https://github.com/peek-travel/cocktail/compare/0.7.0...0.8.0
[0.7.0]: https://github.com/peek-travel/cocktail/compare/0.6.0...0.7.0
[0.6.0]: https://github.com/peek-travel/cocktail/compare/0.5.3...0.6.0
Expand Down
3 changes: 3 additions & 0 deletions lib/cocktail/parser/i_calendar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ defmodule Cocktail.Parser.ICalendar do
end
end

# backwards compatible parsing for schedules generated pre-0.8
defp parse_rrule_option("BYTIME=" <> times_string), do: parse_rrule_option("X-BYTIME=" <> times_string)

defp parse_rrule_option("X-BYTIME=" <> times_string) do
with {:ok, times} <- parse_times_string(times_string) do
{:ok, {:times, times |> Enum.reverse()}}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Cocktail.Mixfile do
use Mix.Project

@version "0.8.0"
@version "0.8.1"

def project do
[
Expand Down
13 changes: 12 additions & 1 deletion test/cocktail/parser/i_calendar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Cocktail.Parser.ICalendarTest do
use ExUnit.Case

alias Cocktail.Rule
alias Cocktail.Validation.{Interval, Day, HourOfDay, MinuteOfHour, SecondOfMinute}
alias Cocktail.Validation.{Interval, Day, HourOfDay, MinuteOfHour, SecondOfMinute, TimeOfDay}

import Cocktail.Parser.ICalendar
import Cocktail.TestSupport.DateTimeSigil
Expand Down Expand Up @@ -95,6 +95,17 @@ defmodule Cocktail.Parser.ICalendarTest do
assert rule.validations[:second_of_minute] == %SecondOfMinute{seconds: [0, 30]}
end

test "parse a pre-0.8 schedule with a BYTIME option to an rrule" do
schedule_string = """
DTSTART:20170810T090000
RRULE:FREQ=DAILY;BYTIME=090000,100000,110000
"""

assert {:ok, schedule} = parse(schedule_string)
assert [%Rule{} = rule] = schedule.recurrence_rules
assert rule.validations[:time_of_day] == %TimeOfDay{times: [{9, 0, 0}, {10, 0, 0}, {11, 0, 0}]}
end

##########
# Errors #
##########
Expand Down

0 comments on commit 24c7b47

Please sign in to comment.