Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove moment.js dependency #126

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Master

- Remove moment.js, move to `date-fns`
- Update dependencies
- Fix missing pkg/config export
- Implement `Flight.queryFlightsByAircraftOperator`
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@
"vitest": "^1.2.2"
},
"dependencies": {
"@date-fns/utc": "^1.1.1",
"@types/sax": "^1.2.7",
"axios": "^1.6.7",
"date-fns": "^3.3.1",
"debug": "^4.3.4",
"invariant": "^2.2.4",
"mkdirp": "^3.0.1",
"moment": "^2.30.1",
"proper-lockfile": "^4.1.2",
"ramda": "~0.28.0",
"soap": "^1.0.0",
Expand Down
21 changes: 14 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Airspace/queryCompleteAIXMDatasets.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import b2bOptions from '../../tests/options';
import { shouldUseRealB2BConnection } from '../../tests/utils';
import { makeAirspaceClient } from '..';
import moment from 'moment';
import { sub } from 'date-fns';
import { describe, test, expect } from 'vitest';

describe('queryCompleteAIXMDatasets', async () => {
Expand All @@ -11,8 +11,8 @@ describe('queryCompleteAIXMDatasets', async () => {
const res = await Airspace.queryCompleteAIXMDatasets({
queryCriteria: {
publicationPeriod: {
wef: moment.utc().subtract(28, 'days').toDate(),
unt: moment.utc().toDate(),
wef: sub(new Date(), { days: 28 }),
unt: new Date(),
},
},
});
Expand Down
4 changes: 2 additions & 2 deletions src/Airspace/retrieveAUP.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeAirspaceClient } from '..';
import moment from 'moment';
import { sub } from 'date-fns';
import b2bOptions from '../../tests/options';
import { AUPSummary } from './types';
import { shouldUseRealB2BConnection } from '../../tests/utils';
Expand All @@ -13,7 +13,7 @@ describe('retrieveAUP', async () => {
// Find some AUP id
const res = await Airspace.retrieveAUPChain({
amcIds: ['LFFAZAMC'],
chainDate: moment.utc().subtract(1, 'day').toDate(),
chainDate: sub(new Date(), { days: 1 }),
});

if (res.data) {
Expand Down
3 changes: 1 addition & 2 deletions src/Airspace/retrieveAUPChain.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import moment from 'moment';
import { describe, expect, test } from 'vitest';
import { makeAirspaceClient } from '..';
import b2bOptions from '../../tests/options';
Expand All @@ -10,7 +9,7 @@ describe('retrieveAUPChain', async () => {
test.runIf(shouldUseRealB2BConnection)('AUP Retrieval', async () => {
const res = await Airspace.retrieveAUPChain({
amcIds: ['LFFAZAMC'],
chainDate: moment.utc().toDate(),
chainDate: new Date(),
});

if (res.data === null) {
Expand Down
3 changes: 1 addition & 2 deletions src/Airspace/retrieveEAUPChain.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import moment from 'moment';
import { describe, expect, test } from 'vitest';
import { makeAirspaceClient } from '..';
import b2bOptions from '../../tests/options';
Expand All @@ -14,7 +13,7 @@ describe('retrieveEAUPChain', async () => {
'EAUP Retrieval',
async () => {
const res = await Airspace.retrieveEAUPChain({
chainDate: moment.utc().toDate(),
chainDate: new Date(),
});

if (res.data === null) {
Expand Down
1 change: 1 addition & 0 deletions src/Common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface NMMap<K, V> {
export type DurationHourMinute = number;
export type DurationMinute = number;
export type DurationHourMinuteSecond = number;
export type Duration = number;

export interface DateYearMonthDayPeriod {
wef?: DateYearMonthDay;
Expand Down
24 changes: 13 additions & 11 deletions src/Flight/queryFlightPlans.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inspect } from 'util';
import { NMB2BError, makeFlightClient } from '..';
import moment from 'moment';
import { sub, add } from 'date-fns';
import b2bOptions from '../../tests/options';
import { FlightOrFlightPlan as B2BFlight } from './types';
import { shouldUseRealB2BConnection } from '../../tests/utils';
Expand All @@ -12,14 +12,18 @@ describe('queryFlightPlans', async () => {
let knownFlight: B2BFlight | undefined;

beforeAll(async () => {
if (!shouldUseRealB2BConnection) {
return;
}

const res = await Flight.queryFlightsByAirspace({
dataset: { type: 'OPERATIONAL' },
includeProposalFlights: false,
includeForecastFlights: false,
trafficType: 'LOAD',
trafficWindow: {
wef: moment.utc().subtract(6, 'hours').toDate(),
unt: moment.utc().add(6, 'hours').toDate(),
wef: sub(new Date(), { hours: 6 }),
unt: add(new Date(), { hours: 6 }),
},
airspace: 'LFEERMS',
});
Expand Down Expand Up @@ -67,14 +71,12 @@ describe('queryFlightPlans', async () => {
airFiled: false,
nonICAOAerodromeOfDestination: false,
estimatedOffBlockTime: {
wef: moment
.utc(knownFlight.flight.flightId.keys?.estimatedOffBlockTime!)
.subtract(30, 'minutes')
.toDate(),
unt: moment
.utc(knownFlight.flight.flightId.keys?.estimatedOffBlockTime!)
.add(30, 'minutes')
.toDate(),
wef: sub(knownFlight.flight.flightId.keys?.estimatedOffBlockTime!, {
minutes: 30,
}),
unt: add(knownFlight.flight.flightId.keys?.estimatedOffBlockTime!, {
minutes: 30,
}),
},
});

Expand Down
6 changes: 3 additions & 3 deletions src/Flight/queryFlightsByAerodrome.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { add, sub } from 'date-fns';
import { makeFlightClient } from '..';
import moment from 'moment';
import b2bOptions from '../../tests/options';
import { shouldUseRealB2BConnection } from '../../tests/utils';
import { describe, test, expect } from 'vitest';
Expand All @@ -9,8 +9,8 @@ describe('queryFlightsByAirspace', async () => {

test.runIf(shouldUseRealB2BConnection)('query in LFPG', async () => {
const trafficWindow = {
wef: moment.utc().subtract(10, 'minutes').toDate(),
unt: moment.utc().add(10, 'minutes').toDate(),
wef: sub(new Date(), { minutes: 10 }),
unt: add(new Date(), { minutes: 10 }),
};

const res = await Flight.queryFlightsByAerodrome({
Expand Down
6 changes: 3 additions & 3 deletions src/Flight/queryFlightsByAerodromeSet.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeFlightClient } from '..';
import moment from 'moment';
import { add, sub } from 'date-fns';
import b2bOptions from '../../tests/options';
import { shouldUseRealB2BConnection } from '../../tests/utils';
import { describe, test, expect } from 'vitest';
Expand All @@ -9,8 +9,8 @@ describe('queryFlightsByAirspace', async () => {

test.runIf(shouldUseRealB2BConnection)('query in LFPG+', async () => {
const trafficWindow = {
wef: moment.utc().subtract(10, 'minutes').toDate(),
unt: moment.utc().add(10, 'minutes').toDate(),
wef: sub(new Date(), { minutes: 10 }),
unt: add(new Date(), { minutes: 10 }),
};

const res = await Flight.queryFlightsByAerodromeSet({
Expand Down
95 changes: 49 additions & 46 deletions src/Flight/queryFlightsByAircraftOperator.test.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
import { makeFlightClient } from '..';
import moment from 'moment';
import { add, sub } from 'date-fns';
import b2bOptions from '../../tests/options';
import { shouldUseRealB2BConnection } from '../../tests/utils';
import { describe, test, expect } from 'vitest';

describe('queryFlightsByAircraftOperator', async () => {
const Flight = await makeFlightClient(b2bOptions);

test.runIf(shouldUseRealB2BConnection)('query Aircraft Operators', async () => {
const trafficWindow = {
wef: moment.utc().subtract(10, 'minutes').toDate(),
unt: moment.utc().add(10, 'minutes').toDate(),
};
test.runIf(shouldUseRealB2BConnection)(
'query Aircraft Operators',
async () => {
const trafficWindow = {
wef: sub(new Date(), { minutes: 10 }),
unt: add(new Date(), { minutes: 10 }),
};

const res = await Flight.queryFlightsByAircraftOperator({
dataset: { type: 'OPERATIONAL' },
includeProposalFlights: false,
includeForecastFlights: false,
trafficType: 'LOAD',
trafficWindow,
aircraftOperators: ['AFR', 'RYR', 'UAE'],
calculationType: 'OCCUPANCY', // Optional, default: 'ENTRY',
});
const res = await Flight.queryFlightsByAircraftOperator({
dataset: { type: 'OPERATIONAL' },
includeProposalFlights: false,
includeForecastFlights: false,
trafficType: 'LOAD',
trafficWindow,
aircraftOperators: ['AFR', 'RYR', 'UAE'],
calculationType: 'OCCUPANCY', // Optional, default: 'ENTRY',
});

/**
* Here, we ensure the returned traffic window matches the supplied
* traffic window, with a 60s precision.
*/
expect(
Math.abs(
res.data.effectiveTrafficWindow.wef.getTime() -
trafficWindow.wef.getTime(),
),
).toBeLessThan(60 * 1000);
/**
* Here, we ensure the returned traffic window matches the supplied
* traffic window, with a 60s precision.
*/
expect(
Math.abs(
res.data.effectiveTrafficWindow.wef.getTime() -
trafficWindow.wef.getTime(),
),
).toBeLessThan(60 * 1000);

expect(
Math.abs(
res.data.effectiveTrafficWindow.unt.getTime() -
trafficWindow.unt.getTime(),
),
).toBeLessThan(60 * 1000);
expect(
Math.abs(
res.data.effectiveTrafficWindow.unt.getTime() -
trafficWindow.unt.getTime(),
),
).toBeLessThan(60 * 1000);

expect(res.data?.flights).toEqual(expect.any(Array));
for (const flight of res.data?.flights) {
expect(flight).toMatchObject({
flight: {
flightId: {
id: expect.any(String),
keys: {
aircraftId: expect.any(String),
aerodromeOfDeparture: expect.stringMatching(/^[A-Z]{4}$/),
aerodromeOfDestination: expect.stringMatching(/^[A-Z]{4}$/),
estimatedOffBlockTime: expect.any(Date),
expect(res.data?.flights).toEqual(expect.any(Array));
for (const flight of res.data?.flights) {
expect(flight).toMatchObject({
flight: {
flightId: {
id: expect.any(String),
keys: {
aircraftId: expect.any(String),
aerodromeOfDeparture: expect.stringMatching(/^[A-Z]{4}$/),
aerodromeOfDestination: expect.stringMatching(/^[A-Z]{4}$/),
estimatedOffBlockTime: expect.any(Date),
},
},
},
},
});
}
});
});
}
},
);
});
6 changes: 3 additions & 3 deletions src/Flight/queryFlightsByAirspace.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeFlightClient } from '..';
import moment from 'moment';
import { add, sub } from 'date-fns';
import b2bOptions from '../../tests/options';
import { shouldUseRealB2BConnection } from '../../tests/utils';
import { describe, test, expect } from 'vitest';
Expand All @@ -9,8 +9,8 @@ describe('queryFlightsByAirspace', async () => {

test.runIf(shouldUseRealB2BConnection)('query in LFEERMS', async () => {
const trafficWindow = {
wef: moment.utc().subtract(10, 'minutes').toDate(),
unt: moment.utc().add(10, 'minutes').toDate(),
wef: sub(new Date(), { minutes: 10 }),
unt: add(new Date(), { minutes: 10 }),
};

const res = await Flight.queryFlightsByAirspace({
Expand Down
6 changes: 3 additions & 3 deletions src/Flight/queryFlightsByMeasure.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { inspect } from 'util';
import { NMB2BError, makeFlightClient, makeFlowClient } from '..';
import moment from 'moment';
import b2bOptions from '../../tests/options';
import { Regulation } from '../Flow/types';
import { beforeAll, describe, expect, test } from 'vitest';
import { shouldUseRealB2BConnection } from '../../tests/utils';
import { sub, add, startOfHour } from 'date-fns';

describe('queryFlightsByMeasure', async () => {
let measure: void | Regulation;
Expand All @@ -15,8 +15,8 @@ describe('queryFlightsByMeasure', async () => {
]);

const window = {
wef: moment.utc().subtract(2, 'hour').startOf('hour').toDate(),
unt: moment.utc().add(2, 'hour').startOf('hour').toDate(),
wef: startOfHour(sub(new Date(), { hours: 2 })),
unt: startOfHour(add(new Date(), { hours: 2 })),
};

beforeAll(async () => {
Expand Down
Loading
Loading