I am using AplineJS Persist to store the date range of Flatpickr to session storage. This is my Flatpickr code:
<div x-data="{
thePicker: null,
init() {
this.thePicker = flatpickr(this.$refs.picker, {
mode: 'range',
minDate: 'today',
inline: false,
dateFormat: 'M j',
showMonths: 2,
defaultDate: this.dateRange,
onChange: (selectedDates) => {this.dateRange = [...selectedDates];}
});
},
}"
>
<div class="flex items-center flex-1 gap-2 overflow-hidden border border-gray-500 rounded-lg">
<input type="text"
x-ref="picker"
placeholder="Add dates"
class="p-0 py-4 placeholder-gray-600 border-0 bg-none focus:ring-0"
>
</div>
</div>
And here is my x-data to store it with persist:
dateRange: $persist([]).using(sessionStorage).as('_x_range'),
The problem I am having is that the date range is being stored in ISO format, like so:
["2024-02-19T07:00:00.000Z","2024-02-22T07:00:00.000Z"]
And I am really struggling to understand how either store it as M j or format it back to M j from ISO.
In this case, I would be totally fine with storing it, for example:
Jan 1 to Jan 8, 2024
But then when displaying the date on the front-end via x-text or x-html, remove the year:
Jan 1 to Jan 8