Skip to content

Commit

Permalink
Improve 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 17, 2023
1 parent 424252c commit a82ad2b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Main

Nothing so far
#### Fixes
* Carry over last base date instead of first base date

## 1.1.1

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Parsed | `00:00` | `24:00` | the Ruby way
### References

* [ICAO Doc 8126: Aeronautical Information Services Manual](https://www.icao.int/NACC/Documents/eDOCS/AIM/8126_unedited_en%20Jul2021.pdf)
* [ICAO Doc 10066: Aeronautical Information Management](https://ffac.ch/wp-content/uploads/2020/11/ICAO-Doc-10066-Aeronautical-Information-Management.pdf)
* [EUROCONTROL Guidelines Operating Procedures AIS Dynamic Data (OPADD)](https://www.eurocontrol.int/sites/default/files/2021-07/eurocontrol-guidelines-opadd-ed4-1.pdf)
* [NOTAM Q Codes](https://www.faa.gov/air_traffic/publications/atpubs/notam_html/appendix_b.html)
* [NOTAM Contractions](https://www.notams.faa.gov/downloads/contractions.pdf)
Expand Down
4 changes: 1 addition & 3 deletions lib/notam/item/d.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ 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).tap do |schedule|
if (date = schedule.first.actives.first).instance_of? AIXM::Schedule::Date
base_date = date # carry over month
end
base_date = schedule.last.last_date || base_date # carry over month
end
end
self
Expand Down
14 changes: 12 additions & 2 deletions lib/notam/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Schedule

# Active dates or days
#
# @note If {#active} lists dates, then {#inactive} must list days and
# @note If {#actives} lists dates, then {#inactives} must list days and
# vice versa.
#
# @return [Array<NOTAM::Schedule::Dates>, Array<NOTAM::Schedule::Days>]
Expand All @@ -41,7 +41,7 @@ class Schedule

# Inactive dates or days
#
# @note If {#inactive} lists dates, then {#active} must list days and
# @note If {#inactives} lists dates, then {#actives} must list days and
# vice versa.
#
# @return [Array<NOTAM::Schedule::Dates>, Array<NOTAM::Schedule::Days>]
Expand Down Expand Up @@ -274,6 +274,16 @@ def active?(at:, xy:)
resolve(on: date, xy: xy).slice(date).times.cover? AIXM.time(at)
end

# Last +actives+ date of the schedule (+inatives+ are ignored).
#
# @return [AIXM::Date, nil] last date or +nil+ if schedule actives are days
def last_date
actives.last.then do |active|
active = active.last if active.respond_to? :last
active if active.instance_of? AIXM::Schedule::Date
end
end

# @abstract
class ScheduleArray < Array
# @return [String]
Expand Down
6 changes: 3 additions & 3 deletions spec/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,12 @@ 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',
simple_implicit_months: 'D) MAY 27 0530-1000, 30 0800-2100, 31 0530-2100, JUN 05 0800-2159, 06-08 0530-2159, 09 0530-1400',
complex_implicit_months: 'D) JUN 13-15 JUL 04-06 0530-2159, 08 10 0800-2159',
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 Expand Up @@ -152,6 +151,7 @@ def schedule
@schedule ||= {
date: '05 1130-1330',
dates: '05 09 13 1130-1330',
dates_with_month: 'FEB 05 MAR 06 1100-1200',
date_range: '05-18 1130-1330',
date_range_with_exception: '05-18 1130-1330 EXC FRI',
date_across_midnight: '08 29 2100-0600',
Expand Down
12 changes: 10 additions & 2 deletions spec/lib/notam/item/d_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
])
end

it "must extract timesheet :implicit_months" do
subject = NOTAM::Item.new(NOTAM::Factory.d[:implicit_months], data: data).parse
it "must extract timesheet :simple_implicit_months" do
subject = NOTAM::Item.new(NOTAM::Factory.d[:simple_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: []>",
Expand All @@ -38,6 +38,14 @@
])
end

it "must extract timesheet :complex_implicit_months" do
subject = NOTAM::Item.new(NOTAM::Factory.d[:complex_implicit_months], data: data).parse
_(subject.schedules.map(&:to_s)).must_equal([
"#<NOTAM::Schedule actives: [2000-06-13..2000-06-15, 2000-07-04..2000-07-06], times: [05:30 UTC..21:59 UTC], inactives: []>",
"#<NOTAM::Schedule actives: [2000-07-08, 2000-07-10], times: [08:00 UTC..21:59 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
24 changes: 24 additions & 0 deletions spec/lib/notam/schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
end
end

it "must extract schedule :dates_with_month" do
schedules = NOTAM::Schedule.parse(NOTAM::Factory.schedule[:dates_with_month], base_date: base_date)
_(schedules.count).must_equal 1
schedules[0].then do |subject|
_(subject.actives).must_be_instance_of NOTAM::Schedule::Dates
_(subject.actives).must_equal [AIXM.date('2000-02-05'), AIXM.date('2000-03-06')]
_(subject.times).must_equal [(AIXM.time('11:00')..AIXM.time('12:00'))]
_(subject.inactives).must_be_instance_of NOTAM::Schedule::Days
_(subject.inactives).must_be :empty?
end
end

it "must extract schedule :date_range" do
schedules = NOTAM::Schedule.parse(NOTAM::Factory.schedule[:date_range], base_date: base_date)
_(schedules.count).must_equal 1
Expand Down Expand Up @@ -454,6 +466,18 @@
_(subject.first.active?(at: Time.utc(2000, 1, 1, 1, 0), xy: AIXM.xy(lat: 49.01614, long: 2.54423))).must_equal false
end
end

describe :last_date do
it "returns the last actives date if dates are used" do
subject = NOTAM::Schedule.parse(NOTAM::Factory.schedule[:dates_with_month], base_date: AIXM.date('2000-01-01'))
_(subject.first.last_date).must_equal AIXM.date('2000-03-06')
end

it "returns nil if days are used" do
subject = NOTAM::Schedule.parse(NOTAM::Factory.schedule[:days], base_date: AIXM.date('2000-01-01'))
_(subject.first.last_date).must_be :nil?
end
end
end

context 'private' do
Expand Down

0 comments on commit a82ad2b

Please sign in to comment.