TDD Implementation Plan — Feature #1908

Updated: 2026-06-26 · Audited: 2026-06-26 · Prepared: 2026-03-03 · Platform: .NET 10, MAUI, C#

FTDT Rest Rules: USA Part 117 §117.25 + CARs 705 Division III — Test-Driven Development plan (tests written before implementation).

Phases

Summary

PhaseHoursNotes
Phase 0 — USA Rest (§117.25)48Highest regulatory density; no existing code
Phase 1 — CARs Rest (§§700.40–700.70)56Complex time-zone logic; most test cases
Phase 2 — Data Model24Foundation — must complete first
Phase 3 — Validation Logic40TDD core; two validator classes
Phase 4 — UI Integration32MAUI controls; multi-platform testing
Phase 5 — Calculator Integration24Wire validators into existing calculators
Phase 6 — Database Schema16SQLite migrations
Phase 7 — Testing & Legal Review48Plus 4–6 weeks elapsed legal review
TOTAL288~7.2 weeks / 2 developers · 14–16 weeks elapsed

Critical path:

Phase 2 (Data Model)
    ↓
Phase 3 (Validation Logic) ←→ Phase 0 (USA specs, in parallel)
                           ←→ Phase 1 (CARs specs, in parallel)
    ↓
Phase 5 (Calculator Integration)
    ↓
Phase 6 (Database Schema)
    ↓
Phase 4 (UI Integration)
    ↓
Phase 7 (Testing + Legal Review)

Phase 0 — USA Rest Requirements (§117.25)

48 hours · Test class: RestRules_USA_117_25_Tests

§117.25 is entirely absent from the current implementation. This phase defines and tests all seven subsections.

Test Requirements (Write First)

SubsectionRequirementTest IDs
§117.25(b)30 consecutive hours free from duty in past 168 hoursTEST-117-B-01 to B-06 (6 tests)
§117.25(c)36-hr rest in new theater = acclimated + satisfies (b)TEST-117-C-01 to C-03 (3 tests)
§117.25(d)56-hr home base rest (trans-theater, >60°, >168h away), 3 physiological nightsTEST-117-D-01 to D-08 (8 tests)
§117.25(e)10-hr pre-FDP rest; minimum 8-hr sleep opportunityTEST-117-E-01 to E-05 (5 tests)
§117.25(f)FCM self-declaration if sleep opportunity < 8 hrsTEST-117-F-01 to F-03 (3 tests)
§117.25(g)Deadhead overage → rest ≥ deadhead duration, min 10 hrsTEST-117-G-01 to G-04 (4 tests)

Total Phase 0 tests: 24 unit tests + 4 integration scenario tests = 28 tests

Implementation Tasks

TaskDescriptionHrs
0B-1Define RestPeriod_USA record/class (Start, End, Duration, SleepOpportunityHours, SelfDeclaredInsufficientRest, IsDeadheadRest)4
0B-2Define RestRequirement_USA value object (RequiredMinimum, RequiredSleepOpportunity, regulation citation, ViolationMessage)3
0B-3Implement §117.25(b) weekly rest checker (scan prior DPs for 30h gap in 168h; handle DST)5
0B-4Implement §117.25(c) acclimation credit3
0B-5Implement §117.25(d) trans-theater home base rest (longitude distance calc, 168h away check, physiological nights checker)8
0B-6Implement §117.25(e)/(f) pre-FDP rest (10h minimum, 8h sleep opportunity, self-declaration flag)5
0B-7Implement §117.25(g) deadhead overage rest4
0B-8Implement PhysiologicalNightChecker helper (given timezone + rest window, count physiological nights 0100–0700)5
0B-9Implement LongitudeDifferenceCalculator helper (ICAO airport code → coordinates → longitude delta)4
0B-10Write/run all Phase 0 tests; TDD red→green7

Phase 1 — CARs Rest Requirements

56 hours · Test class: RestRules_CAN_700_Tests

Current CalculatorRest_CAN.cs Status

SectionStatus
§700.40(1) baseline rest calculation❌ Missing — only exceeded case handled
§700.40(2) exceeded by 1h+✅ Implemented — ExceededReason.Duty branch
§700.41 disruptive schedules❌ Missing
§700.42 time zone difference rest❌ Missing
§700.43 positioning rest⚠️ Stub only — ExceededReason.Positioning branch is empty
§700.50 split duty extension❌ Missing
§700.51 consecutive FDP limits❌ Missing
§700.60(7) post-augmented rest❌ Missing
§700.63(3) post-extension rest✅ Implemented — ExceededReason.UOC branch
§700.70 reserve rest❌ Missing — RAP/RDP durations exist, rest calc missing

Test Requirements (Write First)

§700.40 tests (6): Home base rest (12h), away rest (10h), suitable accommodation option (10h), exceeded rest calculation at 1h+, 2h30m+, and <1h threshold.

§700.41 tests (6): Late-to-early transition, early-to-late transition, 4h TZ exemption, non-triggered case, local night's rest boundary (≥9h in 22:30–09:30).

§700.42 tests (9): Away with 4h TZ diff (11h), >4h TZ diff (14h), returning home in 7 combinations of TZ diff × away duration × WOCL. Canadian TZ recognition (incl. NL).

§700.43 tests (5): No trigger, ≤3h overage, >3h overage, floor check, consent requirement.

§700.50 tests (6): 06:00–23:59 break credit, 00:00–05:59 break credit, <60min break, night duty 3-night limit, 4-night violation, reserve split duty +2h.

§700.70 tests (17): Advance notice (12h / 32h WOCL), RAP duration boundaries (14h), inter-RAP rest (10h), RDP max by start time (5 rows), augmented extensions (3 rows), WOCL extension credit, start time change violations.

Total Phase 1 tests: 43 unit tests + 6 integration scenario tests = 49 tests

Implementation Tasks

TaskDescriptionHrs
1B-1Define RestPeriod_CAN record4
1B-2§700.40(1) baseline rest (home/away; accommodation modifier)4
1B-3§700.40(2) exceeded rest (complete existing stub)2
1B-4§700.41 disruptive schedule rest5
1B-5§700.42 TZ-difference rest (full branching logic)10
1B-6§700.43 positioning rest (complete stub)4
1B-7§700.50 split duty credit formula (100%/50% with 45-min deduction; night duty count)4
1B-8§700.51 consecutive FDP checker4
1B-9§700.70 reserve rest rules (advance notice, RAP cap, inter-RAP rest, RDP max, augmented extensions, WOCL extension)10
1B-10Implement LocalNightRestChecker_CAN helper (≥9h within 22:30–09:30 acclimatized)3
1B-11Write/run all Phase 1 tests; TDD red→green6

Phase 2 — Data Model Enhancements

24 hours · Must complete before all other phases

New Properties Required

ClassNew Properties
DutyPeriod basePreDutyRestStart, PreDutyRestEnd, IsAtHomeBase, HasSuitableAccommodation
DutyPeriod_USAHomeBase, SleepOpportunityHours, InsufficientSleepSelfDeclared, IsDeadheadFDP, TotalDeadheadDuration, WeeklyRestWindowStart, LongitudeTraveledInCurrentTrip, HoursAwayFromHomeBase
DutyPeriod_CANHasFRMSExemption, FRMSExemptionNumber, TZDifferenceFromHomeHours, TimeAwayFromHomeBaseHours, HoursAwayFromHomeConsecutive
ResultsMinimumRestRequired, MinimumRestEnd, RestViolations (List<string>), WeeklyRestCompliant, PreDutyRestCompliant, TransTheaterRestRequired, NightsRequiredAfterReturn

20 data model tests. All new properties must raise INotifyPropertyChanged and have XML doc comments citing the relevant regulation. New columns are nullable or have safe defaults — no breaking SQLite changes.

Phase 3 — Validation Logic

40 hours · Two static validator classes

Each violation message includes the specific regulation citation (e.g., "§117.25(e): Pre-FDP rest is 9h20m; minimum required is 10h"). 20 validator tests.

Phase 4 — UI Integration

32 hours · ViewModel tests + MAUI views

New Views: RestPeriodInputView_USA.xaml, RestPeriodInputView_CAN.xaml, WeeklyRestTracker30h component, HomeBaseRestTracker56h component, WOCL warning banner.

10 ViewModel tests. No dialog alerts or DisplayAlertAsync in Services or Validators (MVVM compliance). Tested on iOS simulator and Android emulator (light + dark mode).

Phase 5 — Calculator Integration

24 hours

Call FTDTRestValidator_USA.ValidateRestRules(dp) from FTDTCalculator_USA and FTDTRestValidator_CAN.ValidateRestRules(dp) from FTDTCalculator_CAN. CalculatorRest_CAN.CalculateMinimumRestWhenExceedingFDP() must be called before the new validator. 10 integration tests. Zero regressions in existing test suite.

Phase 6 — Database Schema

16 hours

New tables: RestPeriod_USA, RestPeriod_CAN. New columns: rest period inputs on DutyPeriod, USA-specific, CAN-specific. Schema version increment. 8 migration tests. All new columns are nullable with safe defaults. Migration is idempotent.

Phase 7 — Testing & Legal Review

48 hours + 4–6 weeks elapsed legal review

15 E2E Tests

StepOwnerElapsed
Prepare USA legal review packageDev4 hrs
ALPA Legal reviews §117.25 implementationALPA Legal2–3 weeks
Prepare CARs review packageDev4 hrs
ALPA Canada legal reviews §§700.40–700.70ALPA Canada2–3 weeks
Developer remediation of findingsDev8 hrs
Legal sign-off and release approvalALPA Legal1 week

Test Coverage Matrix

RegulationTest IDsPhase
§117.25(b) 30h weekly rest in 168hTEST-117-B-01–060
§117.25(c) Theater acclimation creditTEST-117-C-01–030
§117.25(d) 56h trans-theater home base restTEST-117-D-01–080
§117.25(e) 10h pre-FDP, 8h sleep oppTEST-117-E-01–050
§117.25(f) Self-declarationTEST-117-F-01–03, TEST-UI-07–080/4
§117.25(g) Deadhead overage restTEST-117-G-01–040
§700.40(1)/(2) Baseline + exceeded FDP restTEST-700-40-01–061
§700.41 Disruptive schedule local nightTEST-700-41-01–061
§700.42 TZ difference restTEST-700-42-01–091
§700.43 Positioning restTEST-700-43-01–051
§700.50 Split duty credit formulaTEST-700-50-01–061
§700.51 Consecutive WOCL FDPsTEST-700-51-01–031
§700.63(3) Post-UOC extension rest(existing in CalculatorRest_CAN.cs)Existing ✅
§700.70(1)/(5)/(6)/(7)/(8)/(9)/(10) Reserve operationsTEST-700-70-01–171
§700.200 FRMS exemptionTEST-VAL-CAN-08, E2E-CAN-083/7

Total unique test cases: 160 (28+49+20+20+10+10+8+15)

Sprint Planning (Option A — Manual, 2 devs)

SprintWeeksDev ADev BTotal
11–2Phase 2: Data Model (24h)Phase 0: Tests + 0B-1 to 0B-4 (20h)44
23–4Phase 0: Complete 0B-5 to 0B-10 (24h)Phase 1: Tests + §700.40–700.41 (26h)50
35–6Phase 3: FTDTRestValidator_USA (20h)Phase 1: Complete §700.42–700.70 (37h)57
47–8Phase 3: FTDTRestValidator_CAN (20h)Phase 5: Calculator Integration (24h)44
59–10Phase 6: Database + Phase 4 ViewModel tests (26h)Phase 4: UI controls (32h)58
611–12Phase 7: E2E tests (24h)Phase 7: Legal packages (8h); E2E fixes (8h)40
713+Legal remediation, regression, release prep (legal review turnaround: 2–4 weeks elapsed)20

Risk Register

#RiskPImpactMitigation
R-01FAA §117.25(d) "168h away" interpretation ambiguousMedHighFile ALPA legal clarification early; implement conservative interpretation pending reply
R-02CARs TZ difference calculations require Transport Canada interpretationHighMedFlag in code comments; legal review in Phase 7
R-03FTDTDataBase.cs path unknown (not in model folder)MedMedVerify early in Sprint 1 (ALPAMobile/Services/)
R-04ALPA API sync doesn't support new rest fieldsHighMedConditional serialization; mark [JsonIgnore] until API updated
R-05Legal review finds implementation error requiring redesignMedHighShare spec documents from Phases 0/1 with legal before Phase 7
R-06DST-aware physiological night counting is buggyHighHighDedicated PhysiologicalNightChecker with 8+ unit tests including DST boundaries
R-07MAUI DateTimePicker TZ behavior inconsistent iOS vs AndroidHighMedUse existing RestOpportunity.SetStartDateOffset pattern as model
R-08§700.50 split duty credit formula ambiguity (when does "break" count?)MedMedTest 60-min boundary explicitly; add §700.50(2) comment in code
R-09Parallel USA + CARs development creates merge conflictsMedLowFeature branches: feature/1908-phase0-usa, feature/1908-phase1-can
R-10Test project doesn't exist or requires setupLowMedCheck for ALPAMobile.Tests before Sprint 1; create if needed (1 day setup)

Appendix — Key Regulatory Differences

TopicUSA §117.25CARs §700.40
Pre-duty rest minimum10h + 8h sleep opp12h home / 10h away (or 10h suitable accommodation)
Weekly rest30h in 168h1 "single day free from duty" in 168h (§700.29(1)(c))
Trans-timezone rest56h + 3 physiological nightsUp to 3 local nights (§700.42, TZ diff dependent)
Night definitionPhysiological night: 0100–0700 home/acclimatedLocal night's rest: ≥9h within 22:30–09:30 acclimatized
WOCL0200–055902:00–05:59 (same)
Acclimation72h in theater OR 36h free from duty<4h TZ diff: 72h in same zone; ≥4h: 96h in same zone
Deadhead restRest ≥ deadhead duration, min 10hNo equivalent; deadhead = positioning (§700.43)
Reserve rest§117.25(e) applies to reserve FDP§700.70(6): 10h between RAPs; RDP limits by start time
FRMSNot in Part 117§700.200 FRMS exemptions available

Files to Create / Modify

New Files

ALPAMobile/Data/Models/FlightTimeDutyTime/RestPeriod_USA.cs
ALPAMobile/Data/Models/FlightTimeDutyTime/RestPeriod_CAN.cs
ALPAMobile/BusinessLogic/FlightTimeDutyTime/FTDTRestValidator_USA.cs
ALPAMobile/BusinessLogic/FlightTimeDutyTime/FTDTRestValidator_CAN.cs
ALPAMobile/BusinessLogic/FlightTimeDutyTime/Helpers/PhysiologicalNightChecker.cs
ALPAMobile/BusinessLogic/FlightTimeDutyTime/Helpers/LongitudeDifferenceCalculator.cs
ALPAMobile/BusinessLogic/FlightTimeDutyTime/Helpers/LocalNightRestChecker_CAN.cs
ALPAMobile/Views/FTDT/RestPeriodInputView_USA.xaml (.cs)
ALPAMobile/Views/FTDT/RestPeriodInputView_CAN.xaml (.cs)
ALPAMobile/Views/FTDT/Components/WeeklyRestTracker30h.xaml (.cs)
ALPAMobile/Views/FTDT/Components/HomeBaseRestTracker56h.xaml (.cs)
ALPAMobile.Tests/FTDT/RestRules_USA_117_25_Tests.cs
ALPAMobile.Tests/FTDT/RestRules_CAN_700_Tests.cs
ALPAMobile.Tests/FTDT/DataModel_RestProperties_Tests.cs
ALPAMobile.Tests/FTDT/FTDTRestValidator_USA_Tests.cs
ALPAMobile.Tests/FTDT/FTDTRestValidator_CAN_Tests.cs
ALPAMobile.Tests/FTDT/RestPeriodViewModel_Tests.cs
ALPAMobile.Tests/FTDT/Calculator_RestIntegration_Tests.cs
ALPAMobile.Tests/Database/Database_RestMigration_Tests.cs
ALPAMobile.Tests/FTDT/E2E/FTDT_E2E_ComplianceTests.cs

Modified Files

ALPAMobile/Data/Models/FlightTimeDutyTime/DutyPeriod.cs
ALPAMobile/Data/Models/FlightTimeDutyTime/Results.cs
ALPAMobile/Data/Models/FlightTimeDutyTime/CalculatorRest_CAN.cs
ALPAMobile/BusinessLogic/FlightTimeDutyTime/FTDTCalculator_USA.cs
ALPAMobile/BusinessLogic/FlightTimeDutyTime/FTDTCalculator_CAN.cs
ALPAMobile/Services/FTDTDataBase.cs  (verify path)
ALPAMobile/Interfaces/FlightTimeDutyTime/IDutyPeriod_USA.cs
ALPAMobile/Interfaces/FlightTimeDutyTime/IDutyPeriod_CAN.cs