tamble / jquery-ui-daterangepicker

A JQuery UI based date range picker.
MIT License
184 stars 110 forks source link

New option for custom formatRangeForDisplay function. #86

Open prototype23 opened 6 years ago

prototype23 commented 6 years ago

A new option 'formatRangeForDisplay' would be helpful. Especially when displaying dates in diff timezone than local.

    function formatRangeForDisplay(range) {
            var dateFormat = options.dateFormat;

            if (typeof options.formatRangeForDisplay === 'function') {
                return options.formatRangeForDisplay();
            } else {
                return $.datepicker.formatDate(dateFormat, range.start) + (+range.end !== +range.start ? options.rangeSplitter + $.datepicker.formatDate(dateFormat, range.end) : '');
            }
        }
prototype23 commented 6 years ago

Well i think this might not be necessary. I was using an altField '@' (timestamp) and my custom preset ranges were parsing the date on the target timezone.

This proved wrong because jQuery datepicker works on local time only. For the story, while the timestamps on the original element value were generated ok, the calendar, when the local timezone was different from the target timezone, was selecting other dates..

I now use an altField: 'yy-mm-dd' and i parse the date on my target timezone only at the end, at the point i want to use the result.