pglejzer / timepicker-ui

timepicker-ui is an easy library with timepicker. Fully wrote with TypeScript. This library is based on Material Design from Google.
MIT License
62 stars 18 forks source link

I need option to set Timezone #14

Closed afnanz7634 closed 1 year ago

afnanz7634 commented 2 years ago

Hi I'm using this picker in my application now I need a new requirement to set TimeZone ( ET & PT ) . any help ?

pglejzer commented 2 years ago

Do you need to set timezone in input? Unfortunately is not possible to do this now. I can try to add this in the next version

pglejzer commented 2 years ago

Can you describe how do you want that timezone option should work? I created something like this but I'm not sure is that what you need.

<div class="test" style="max-width: 300px">
   <input type="text" class="timepicker-ui-input" />
</div>
const test = document.querySelector('.test') as HTMLDivElement;
const testPicker = new TimepickerUI(test, {
  clockType: '24h',
});

const options1 = {
  timeZone: 'Asia/Shanghai',
  year: 'numeric',
  month: 'numeric',
  day: 'numeric',
  hour: 'numeric',
  minute: 'numeric',
  second: 'numeric',
};

const formatter = new Intl.DateTimeFormat([], options1 as any);

const formatterSplitted = formatter.format(new Date()).split(',')[1];
const formatterJoin = formatterSplitted.split(':').slice(0, -1).join(':');
const inputElement = test.querySelector('input') as HTMLInputElement;
inputElement.value = formatterJoin.trim();

testPicker.create();