Skip to content

Commit

Permalink
fix: Add property check before updating shorthand for english locale
Browse files Browse the repository at this point in the history
Signed-off-by: Akshat Patel <[email protected]>
  • Loading branch information
Akshat55 committed Aug 24, 2023
1 parent 229f87d commit 6ddf745
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/datepicker/datepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,33 @@ import {
AfterViewChecked,
AfterViewInit,
ViewChild,
AfterContentInit,
OnInit,
SimpleChange
} from "@angular/core";
import rangePlugin from "flatpickr/dist/plugins/rangePlugin";
import flatpickr from "flatpickr";
import { NG_VALUE_ACCESSOR } from "@angular/forms";
import { carbonFlatpickrMonthSelectPlugin } from "./carbon-flatpickr-month-select";
import languages from "flatpickr/dist/l10n/index";
import * as languages from "flatpickr/dist/l10n/index";
import { DatePickerInput } from "carbon-components-angular/datepicker-input";
import { I18n } from "carbon-components-angular/i18n";

// Due to type error, we have to use square brackets property accessor
(languages.default["en"].weekdays.shorthand as string[])
= languages.default["en"].weekdays.longhand.map(day => {
if (day === "Thursday") {
return "Th";
}
return day.charAt(0);
});
/**
* Due to type error, we have to use square brackets property accessor
* There is a webpack issue when attempting to access exported languages from flatpickr l10n Angular 14+ apps
* languages.default[locale] fails in app consuming CCA library but passes in test
* languages.default.default[locale] fails in test but works in app consuming CCA library.
*
* To please both scenarios, we are adding a condition to prevent tests from failing
*/
if (languages.default?.default["en"]?.weekdays) {
(languages.default.default["en"].weekdays.shorthand as string[]) = languages.default.default["en"].weekdays.longhand.map(day => {
if (day === "Thursday") {
return "Th";
}
return day.charAt(0);
});
}

/**
* [See demo](../../?path=/story/components-date-picker--single)
Expand Down Expand Up @@ -221,7 +228,7 @@ export class DatePicker implements
mode: this.range ? "range" : "single",
plugins,
dateFormat: this.dateFormat,
locale: languages.default[this.language]
locale: languages.default?.default[this.language] || languages.default[this.language]
});
}

Expand Down

0 comments on commit 6ddf745

Please sign in to comment.