Skip to content

Commit

Permalink
change date format used in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 26, 2019
1 parent 8e0817f commit fe8258b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
11 changes: 10 additions & 1 deletion src/components/RecursiveForm/RecursiveForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ export default {
* @param {*} value - New value for current option.
*/
handler(value) {
this.$configBus.$emit(EVENTS.UPDATE, { name: this.mutableOption.name, value });
this.$configBus.$emit(EVENTS.UPDATE,
{
name: this.mutableOption.name,
value,
});
},
deep: typeof selected !== 'string',
immediate: true,
Expand Down Expand Up @@ -392,6 +396,11 @@ export default {
*/
getChoicesByDependency({ name }) {
const dependencies = this.$configBus.dependencies[this.$configBus.currentCarrier];
if (!dependencies) {
return;
}
const { dependency } = this.mutableOption;
let dependencyName = dependency.name;
Expand Down
9 changes: 9 additions & 0 deletions src/config/configBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,18 @@ export const createConfigBus = () => {

/**
* The object where settings will be stored.
*
* @type {Object}
*/
values: {},

/**
* The object where the values that are sent to the external platform will be stored. Similar to `this.values`,
* but this object is tweaked to comply with our API and conventions and to maximize readability for the
* developers using it.
*
* @type {Object}
*/
exportValues: {},

/**
Expand Down
29 changes: 10 additions & 19 deletions src/data/delivery/getDeliveryDates.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import * as SETTINGS from '@/config/data/settingsConfig';
import { configBus } from '@/config/configBus';

/**
* Helper function for date.toLocaleDateString with locale from the config bus and default format.
*
* @param {Date} date - Date to format.
* @param {Object} format - The format to apply.
*
* @returns {string}
*/
function toLocaleDateString(date, format = { month: 'numeric', day: 'numeric', year: 'numeric' }) {
return date.toLocaleDateString(configBus.get(SETTINGS.LOCALE), format);
}

/**
* @param {MyParcel.DeliveryOption[]} deliveryOptions - Delivery options object.
*
Expand All @@ -28,21 +16,24 @@ export function getDeliveryDates(deliveryOptions) {
if (configBus.get(SETTINGS.DELIVERY_DAYS_WINDOW) === 0) {
return [
{
name: toLocaleDateString(new Date(deliveryOptions[0].date.date)),
name: new Date(deliveryOptions[0].date.date).toString(),
label: '',
},
];
}

return deliveryOptions.map(({ date: option }) => {
const date = new Date(option.date);
const name = toLocaleDateString(date);
const name = date.toISOString();

const dateString = toLocaleDateString(date, {
weekday: 'long',
month: 'long',
day: 'numeric',
});
const dateString = date.toLocaleDateString(
configBus.get(SETTINGS.LOCALE),
{
weekday: 'long',
month: 'long',
day: 'numeric',
}
);

const label = dateString.charAt(0).toUpperCase() + dateString.slice(1);

Expand Down

0 comments on commit fe8258b

Please sign in to comment.