UNPKG

clock-format-utility

Version:

Utility that can detect clock format (12/24 hour) and can set clock format for moment

1 lines 978 B
Object.defineProperty(exports,"__esModule",{value:true});var specificClockConfig={'en-SV':'24'};var detectDeviceLocale=exports.detectDeviceLocale=function detectDeviceLocale(){try{var deviceInfo=require('react-native-device-info');return deviceInfo.getDeviceLocale();}catch(e){try{return window.navigator.languages&&window.navigator.languages.length>0?window.navigator.languages[0]:window.navigator.language||window.navigator.userLanguage;}catch(ex){return'en-US';}}};var detectDeviceClockFormat=exports.detectDeviceClockFormat=function detectDeviceClockFormat(){var locale=arguments.length>0&&arguments[0]!==undefined?arguments[0]:detectDeviceLocale();if(specificClockConfig[locale]){return specificClockConfig[locale];}var timeString=new Date().toLocaleTimeString(locale),foundAMorPM=timeString.indexOf('AM')>-1||timeString.indexOf('PM')>-1;return foundAMorPM?'12':'24';};exports.default={detectDeviceClockFormat:detectDeviceClockFormat,detectDeviceLocale:detectDeviceLocale};