Skip to content

Commit

Permalink
switch from dayjs to momentjs for utc mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewmeyer committed Aug 11, 2018
1 parent 101c379 commit bf596e5
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -28,7 +28,6 @@
},
"homepage": "https://github.com/r-spacex/SpaceX-API",
"dependencies": {
"dayjs": "^1.7.5",
"koa": "^2.5.2",
"koa-compress": "^3.0.0",
"koa-helmet": "^4.0.0",
Expand All @@ -38,6 +37,7 @@
"koa-router": "^7.4.0",
"koa2-cors": "^2.0.6",
"lower-case": "^1.1.4",
"moment": "^2.22.2",
"mongodb": "^3.1.1",
"path": "^0.12.7",
"request": "^2.88.0",
Expand Down
6 changes: 3 additions & 3 deletions scripts/roadster.js
Expand Up @@ -2,13 +2,13 @@

const MongoClient = require('mongodb');
const request = require('request-promise-native');
const dayjs = require('dayjs');
const moment = require('moment');
const shell = require('shelljs');

shell.config.silent = true;

const today = dayjs().format('YYYY-MMM-DD HH:mm:ss');
const tomorrow = dayjs().add(1, 'day').format('YYYY-MMM-DD HH:mm:ss');
const today = moment().format('YYYY-MMM-DD HH:mm:ss');
const tomorrow = moment().add(1, 'day').format('YYYY-MMM-DD HH:mm:ss');

const orbitURL = `https://ssd.jpl.nasa.gov/horizons_batch.cgi?batch=1&
COMMAND= '-143205'&
Expand Down
6 changes: 2 additions & 4 deletions src/builders/launch-query.js
@@ -1,7 +1,7 @@

// Required to correctly output ObjectID's
const ObjectId = require('mongodb').ObjectID;
const dayjs = require('dayjs');
const moment = require('moment');
const dateRange = require('../utilities/date_range');

/**
Expand All @@ -21,8 +21,6 @@ module.exports = (q) => {

if (q.start && (q.final || q.end)) {
query.launch_date_utc = dateRange(q);
console.log(q);
console.log(dateRange(q));
}

if (q.flight_number) {
Expand All @@ -35,7 +33,7 @@ module.exports = (q) => {

if (q.launch_date_utc) {
// Allow any valid date format
const date = dayjs(q.launch_date_utc);
const date = moment(q.launch_date_utc);
try {
query.launch_date_utc = date.toISOString();
} catch (e) {
Expand Down
10 changes: 5 additions & 5 deletions src/utilities/date_range.js
@@ -1,5 +1,5 @@

const dayjs = require('dayjs');
const moment = require('moment');

/**
* Return date range object for mongo find query
Expand All @@ -12,11 +12,11 @@ module.exports = (q) => {
let end;
// See if date is unix, if so, add miliseconds
if (/^[0-9]*$/.test(q.start && (q.final || q.end))) {
start = dayjs(q.start * 1000);
end = dayjs(q.final * 1000 || q.end * 1000);
start = moment.utc(q.start * 1000);
end = moment.utc(q.final * 1000 || q.end * 1000);
} else {
start = dayjs(q.start);
end = dayjs(q.final || q.end);
start = moment.utc(q.start);
end = moment.utc(q.final || q.end);
}

return { $gte: start.toISOString(), $lte: end.toISOString() };
Expand Down
2 changes: 1 addition & 1 deletion test/routes/v2-launches.test.js
Expand Up @@ -139,7 +139,7 @@ test('It should return no launches due to invalid date', async () => {
test('It should return no launches due to invalid UTC date', async () => {
const response = await request(app.callback()).get('/v2/launches?launch_date_utc=2011-25-05T14:48:00.000Z');
expect(response.statusCode).toBe(200);
expect(response.body.length).toBeGreaterThanOrEqual(66);
expect(response.body).toEqual([]);
});

//------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/utilities/date_parse.test.js
Expand Up @@ -7,5 +7,5 @@ test('It should return the correct date comparison object', () => {
final: '2017-06-25',
};
const response = dateParse(query);
expect(response).toEqual({ $gte: '2017-06-22T05:00:00.000Z', $lte: '2017-06-25T05:00:00.000Z' });
expect(response).toEqual({ $gte: '2017-06-22T00:00:00.000Z', $lte: '2017-06-25T00:00:00.000Z' });
});
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -855,10 +855,6 @@ data-urls@^1.0.0:
whatwg-mimetype "^2.0.0"
whatwg-url "^6.4.0"

dayjs@^1.7.5:
version "1.7.5"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.7.5.tgz#14715cb565d1f8cb556a8531cb14bf1fc33067cc"

debug@0.7.4:
version "0.7.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-0.7.4.tgz#06e1ea8082c2cb14e39806e22e2f6f757f92af39"
Expand Down Expand Up @@ -3047,6 +3043,10 @@ mkdirp@^0.5.0, mkdirp@^0.5.1:
dependencies:
minimist "0.0.8"

moment@^2.22.2:
version "2.22.2"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"

mongodb-core@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/mongodb-core/-/mongodb-core-3.1.0.tgz#af91f36fd560ed785f4e61e694432df4d3698aad"
Expand Down

0 comments on commit bf596e5

Please sign in to comment.