clock-format-utility
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,1 +0,1 @@ | ||
Object.defineProperty(exports,"__esModule",{value:true});var detectDeviceLocale=exports.detectDeviceLocale=function detectDeviceLocale(){try{var deviceInfo=require('react-native-device-info');return deviceInfo.getDeviceLocale();}catch(e){return window.navigator.languages&&window.navigator.languages.length>0?window.navigator.languages[0]:window.navigator.language||window.navigator.userLanguage;}};var detectDeviceClockFormat=exports.detectDeviceClockFormat=function detectDeviceClockFormat(){var locale=arguments.length>0&&arguments[0]!==undefined?arguments[0]:detectDeviceLocale();var timeString=new Date().toLocaleString(locale);var foundAMorPM=timeString.indexOf('AM')>-1||timeString.indexOf('PM')>-1;return foundAMorPM?'12':'24';};exports.default={detectDeviceClockFormat:detectDeviceClockFormat,detectDeviceLocale:detectDeviceLocale}; | ||
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){return window.navigator.languages&&window.navigator.languages.length>0?window.navigator.languages[0]:window.navigator.language||window.navigator.userLanguage;}};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}; |
@@ -1,1 +0,1 @@ | ||
Object.defineProperty(exports,"__esModule",{value:true});exports.setMomentLocaleClockFormat=exports.replaceFormatInString=exports.setMomentLocale=undefined;var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _detect=require('./detect');var setMomentLocale=exports.setMomentLocale=function setMomentLocale(){var locale=arguments.length>0&&arguments[0]!==undefined?arguments[0]:(0,_detect.detectDeviceLocale)();return require('moment').locale(locale);};var replaceFormatInString=exports.replaceFormatInString=function replaceFormatInString(oldValue){var clockFormat=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'24';return clockFormat==='24'?oldValue.replace('h:mm A','HH:mm'):oldValue.replace('HH:mm','h:mm A');};var setMomentLocaleClockFormat=exports.setMomentLocaleClockFormat=function setMomentLocaleClockFormat(){var clockFormat=arguments.length>0&&arguments[0]!==undefined?arguments[0]:(0,_detect.detectDeviceClockFormat)();var locale=arguments.length>1&&arguments[1]!==undefined?arguments[1]:require('moment').locale();var moment=require('moment');var longDateFormat=moment.localeData(locale)._longDateFormat;if(clockFormat==='24'){moment.updateLocale(locale,{longDateFormat:_extends({},longDateFormat,{LT:'HH:mm',LTS:'HH:mm:ss',LLL:longDateFormat.LLL&&replaceFormatInString(longDateFormat.LLL),LLLL:longDateFormat.LLLL&&replaceFormatInString(longDateFormat.LLLL),lll:longDateFormat.lll&&replaceFormatInString(longDateFormat.lll),llll:longDateFormat.llll&&replaceFormatInString(longDateFormat.llll)})});}else{moment.updateLocale(locale,{longDateFormat:_extends({},longDateFormat,{LT:'h:mm A',LTS:'h:mm:ss A',LLL:longDateFormat.LLL&&replaceFormatInString(longDateFormat.LLL,'12'),LLLL:longDateFormat.LLLL&&replaceFormatInString(longDateFormat.LLLL,'12'),lll:longDateFormat.lll&&replaceFormatInString(longDateFormat.lll,'12'),llll:longDateFormat.llll&&replaceFormatInString(longDateFormat.llll,'12')})});}}; | ||
Object.defineProperty(exports,"__esModule",{value:true});exports.setMomentLocaleClockFormat=exports.replaceFormatInString=exports.setMomentLocale=undefined;var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _detect=require('./detect');var setMomentLocale=exports.setMomentLocale=function setMomentLocale(){var locale=arguments.length>0&&arguments[0]!==undefined?arguments[0]:(0,_detect.detectDeviceLocale)();return require('moment').locale(locale);};var replaceFormatInString=exports.replaceFormatInString=function replaceFormatInString(oldValue){var clockFormat=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'24';return clockFormat==='24'?oldValue.replace('h:mm A','HH:mm'):oldValue.replace('HH:mm','h:mm A');};var setMomentLocaleClockFormat=exports.setMomentLocaleClockFormat=function setMomentLocaleClockFormat(){var clockFormat=arguments.length>0&&arguments[0]!==undefined?arguments[0]:(0,_detect.detectDeviceClockFormat)();var locale=arguments.length>1&&arguments[1]!==undefined?arguments[1]:require('moment').locale();var moment=require('moment'),longDateFormat=moment.localeData(locale)._longDateFormat;if(clockFormat==='24'){moment.updateLocale(locale,{longDateFormat:_extends({},longDateFormat,{LT:'HH:mm',LTS:'HH:mm:ss',LLL:longDateFormat.LLL&&replaceFormatInString(longDateFormat.LLL),LLLL:longDateFormat.LLLL&&replaceFormatInString(longDateFormat.LLLL),lll:longDateFormat.lll&&replaceFormatInString(longDateFormat.lll),llll:longDateFormat.llll&&replaceFormatInString(longDateFormat.llll)})});}else{moment.updateLocale(locale,{longDateFormat:_extends({},longDateFormat,{LT:'h:mm A',LTS:'h:mm:ss A',LLL:longDateFormat.LLL&&replaceFormatInString(longDateFormat.LLL,'12'),LLLL:longDateFormat.LLLL&&replaceFormatInString(longDateFormat.LLLL,'12'),lll:longDateFormat.lll&&replaceFormatInString(longDateFormat.lll,'12'),llll:longDateFormat.llll&&replaceFormatInString(longDateFormat.llll,'12')})});}}; |
{ | ||
"name": "clock-format-utility", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Utility that can detect clock format (12/24 hour) and can set clock format for moment", | ||
@@ -9,3 +9,4 @@ "main": "lib/index.js", | ||
"build": "babel src --out-dir lib", | ||
"prepublish": "npm test && npm run build" | ||
"prepublish": "npm test && npm run build", | ||
"prepush": "npm test" | ||
}, | ||
@@ -37,2 +38,5 @@ "repository": { | ||
"resetMocks": true, | ||
"testPathIgnorePatterns": [ | ||
"lib" | ||
], | ||
"setupTestFrameworkScriptFile": "./setupTests.js", | ||
@@ -39,0 +43,0 @@ "collectCoverageFrom": [ |
# clock-format-utility | ||
[ ![Codeship Status for robertherber/clock-format-utility](https://app.codeship.com/projects/78dc88f0-7cf6-0135-5c44-361f0802280c/status?branch=master)](https://app.codeship.com/projects/245786) | ||
This is a tiny library used to set 12/24 hour clock formatting. | ||
@@ -4,0 +6,0 @@ The main use-case is to **support non-standard language/localization combinations** - specifically in moment. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6900
23