Skip to content

Commit

Permalink
add timezone info
Browse files Browse the repository at this point in the history
  • Loading branch information
skylinezum committed Aug 10, 2020
1 parent 245cf74 commit a728487
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
7 changes: 6 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uteam-tw/gogovan-plus",
"version": "1.0.5",
"version": "1.0.6",
"description": "gogovan plus api wrapper",
"main": "./lib/index.js",
"scripts": {
Expand Down Expand Up @@ -46,6 +46,7 @@
},
"dependencies": {
"@types/regenerator-runtime": "^0.13.0",
"date-fns-tz": "^1.0.10",
"phin": "^3.5.0",
"regenerator-runtime": "^0.13.7"
}
Expand Down
18 changes: 15 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'regenerator-runtime/runtime';
import phin from 'phin';
import format from 'date-fns/fp/format';
import utcToZonedTime from 'date-fns-tz/fp/utcToZonedTime';

type Vehicle = 'motorcycle' | 'struck' | 'mtruck';

Expand Down Expand Up @@ -187,10 +188,17 @@ export default class Gogovanplus {
private email: string;
private password: string;
private baseURL: string;
constructor(newEmail: string, newPassword: string, endpointURL: string) {
private timezone: string;
constructor(
newEmail: string,
newPassword: string,
endpointURL: string,
timezone: string = 'Asia/Taipei'
) {
this.email = newEmail;
this.password = newPassword;
this.baseURL = endpointURL;
this.timezone = timezone;
}

/*
Expand Down Expand Up @@ -218,7 +226,9 @@ export default class Gogovanplus {
order: {
booth: booth.toString(),
carry: carry.toString(),
pickup_time: format('yyyy/MM/dd HH:mm')(pickup_time),
pickup_time: format('yyyy/MM/dd HH:mm')(
utcToZonedTime(this.timezone)(pickup_time)
),
...restParams,
},
},
Expand Down Expand Up @@ -261,7 +271,9 @@ export default class Gogovanplus {
booth: 'false',
carry: 'false',
need_insulation_bags: !!need_insulation_bags ? 'true' : 'false',
pickup_time: format('yyyy/MM/dd HH:mm')(pickup_time),
pickup_time: format('yyyy/MM/dd HH:mm')(
utcToZonedTime(this.timezone)(pickup_time)
),
...restParams,
},
},
Expand Down
6 changes: 4 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ dotenv.config();
const gogovan = new Gogovanplus(
process.env.API_EMAIL || '',
process.env.API_PASSWORD || '',
process.env.API_ENDPOINT || ''
process.env.API_ENDPOINT || '',
'Asia/Taipei'
);

const sampleGetPrice = {
Expand Down Expand Up @@ -41,7 +42,7 @@ const sampleCreateOrder = {
need_insulation_bags: false,
note: '',
phone_number: '+88622272399',
pickup_time: addMinutes(60)(new Date()),
pickup_time: addMinutes(60 * 16)(new Date()),
receiver_name: 'Frank Su Jhih Wei',
receiver_phone_number: '+886955940336',
vehicle: 'motorcycle' as 'motorcycle',
Expand All @@ -51,6 +52,7 @@ const prevOrderId = '13791';

describe('order api', () => {
it('should get price', async () => {
jest.setTimeout(30000);
try {
const res = await gogovan.getPrice(sampleGetPrice);
console.log('get price', JSON.stringify(res, null, 2));
Expand Down

0 comments on commit a728487

Please sign in to comment.