Skip to content

Commit

Permalink
bump to v1.1.5 - more store hour helper getters and for store locatio…
Browse files Browse the repository at this point in the history
…n, determine if 24 hours, closed etc
  • Loading branch information
roncodes committed Jan 11, 2022
1 parent 9f5ba7a commit e7ab850
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/@fleetbase/storefront.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/@fleetbase/storefront.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/storefront.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/storefront.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/storefront.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/storefront.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/storefront",
"version": "1.1.4",
"version": "1.1.5",
"description": "Fleetbase Storefront JS & Node SDK",
"main": "dist/cjs/storefront.js",
"module": "dist/esm/storefront.js",
Expand Down
28 changes: 27 additions & 1 deletion src/resources/store-hour.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ export default class StoreHour extends Resource {
return this.getAttribute('day');
}

get isClosed() {
return this.getAttribute('start') === null && this.getAttribute('end') === null;
}

get is24Hours() {
const start = this.startDateInstance;
const end = this.endDateInstance;
const diff = Math.abs(start - end);
const hours = Math.floor(diff / 1000 / 60) / 60;

return hours > 23;
}

get startDateInstance() {
if (!this.hasAttribute('start')) {
return null;
Expand All @@ -34,14 +47,27 @@ export default class StoreHour extends Resource {
return parse(end, format, new Date());
}

get humanReadableHours() {
get humanReadableHoursRange() {
if (!isValid(this.startDateInstance) || !isValid(this.endDateInstance)) {
return `${this.start} - ${this.end}`;
}

return `${format(this.startDateInstance, 'p')} - ${format(this.endDateInstance, 'p')}`;
}

get humanReadableHours() {
if (this.isClosed) {
return 'Closed';
}

if (this.is24Hours) {
return '24 Hours';
}

return this.humanReadableHoursRange;
}


// remove default resource methods
create() {
throw new Error('There is no create() method store location!');
Expand Down
11 changes: 11 additions & 0 deletions src/resources/store-location.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Resource from '../resource';
import StoreHour from './store-hour';
import { Collection } from '@fleetbase/sdk';
import { format } from 'date-fns';

export default class StoreLocation extends Resource {
constructor(attributes = {}, adapter, options = {}) {
Expand All @@ -19,6 +20,16 @@ export default class StoreLocation extends Resource {
return new Collection(this.getAttribute('hours').map(attributes => new StoreHour(attributes)));
}

get isAlwaysOpen() {
return this.hours.every((hour) => hour?.is24Hours);
}

get today() {
const today = format(new Date(), 'EEEE');

return this.schedule[today];
}

get schedule() {
const schedule = {};
const week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
Expand Down

0 comments on commit e7ab850

Please sign in to comment.