Skip to content

Commit

Permalink
Carry over base date for multiple D-item elements
Browse files Browse the repository at this point in the history
  • Loading branch information
svoop committed Jun 7, 2023
1 parent 3b8993e commit aa2c966
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Main

Nothing so far
#### Fixes
* Carry over base date for multiple D-item elements which partially omit to
mention the month in every element

## 1.1.0

Expand Down
6 changes: 5 additions & 1 deletion lib/notam/item/d.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class D < Item
def parse
base_date = AIXM.date(data[:effective_at])
@schedules = text.sub(/\AD\)/, '').split(',').flat_map do |string|
Schedule.parse(string, base_date: base_date)
Schedule.parse(string, base_date: base_date).tap do |schedule|
if (date = schedule.first.actives.first).instance_of? AIXM::Schedule::Date
base_date = date # carry over month
end
end
end
self
rescue
Expand Down
3 changes: 3 additions & 0 deletions spec/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ def d
@d ||= {
two_months: 'D) FEB 08-28 2000-2200, MAR 01-05 1800-2200',
one_month: 'D) 16 23 H24, 19 21-24 28 0600-1700',
implicit_months: 'D) MAY 27 0530-1000, 30 0800-2100, 31 0530-2100, JUN 05 0800-2159, 06-08 0530-2159, 09 0530-1400',
weekdays: 'D) MON-FRI 0700-1100 1300-1700',
date_with_exception: 'D) FEB 01-MAR 31 0700-1100 EXC FRI',
daytime: 'D) SR-SS',
invalid: 'D) 22 0700-1700 23 0430-1800 24 0430-1400'


}
end

Expand Down
11 changes: 11 additions & 0 deletions spec/lib/notam/item/d_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
])
end

it "must extract timesheet :implicit_months" do
subject = NOTAM::Item.new(NOTAM::Factory.d[:implicit_months], data: data).parse
_(subject.schedules.map(&:to_s)).must_equal([
"#<NOTAM::Schedule actives: [2000-05-27], times: [05:30 UTC..10:00 UTC], inactives: []>",
"#<NOTAM::Schedule actives: [2000-05-30], times: [08:00 UTC..21:00 UTC], inactives: []>",
"#<NOTAM::Schedule actives: [2000-05-31], times: [05:30 UTC..21:00 UTC], inactives: []>",
"#<NOTAM::Schedule actives: [2000-06-05], times: [08:00 UTC..21:59 UTC], inactives: []>",
"#<NOTAM::Schedule actives: [2000-06-06..2000-06-08], times: [05:30 UTC..21:59 UTC], inactives: []>", "#<NOTAM::Schedule actives: [2000-06-09], times: [05:30 UTC..14:00 UTC], inactives: []>"
])
end

it "must extract timesheet :weekdays" do
subject = NOTAM::Item.new(NOTAM::Factory.d[:weekdays], data: data).parse
_(subject.schedules.map(&:to_s)).must_equal([
Expand Down

0 comments on commit aa2c966

Please sign in to comment.