-
Notifications
You must be signed in to change notification settings - Fork 29
/
LocaleBaseClass.js
34 lines (26 loc) · 1.02 KB
/
LocaleBaseClass.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Platform, NativeModules } from 'react-native';
const NativeLocale = NativeModules.Locale;
const warning = require('fbjs/lib/warning');
class LocaleBaseClass {
static constants() {
return NativeLocale;
}
static numberFromDecimalString(number : string) {
return NativeLocale.numberFromDecimalString(number);
}
static decimalStyle(number : number) {
return NativeLocale.decimalStyle(number);
}
static validateDateFormatStyle(style : string) {
let valid = ['full', 'long', 'medium', 'short', 'none'];
if(Platform.OS == 'ios')
valid.push('default');
return valid.indexOf(style) >= 0;
}
static dateFormat(date, dateStyle : string, timeStyle : string) {
warning(LocaleBaseClass.validateDateFormatStyle(dateStyle), 'Locale: DateStyle must be one of [full/long/medium/short/none]');
warning(LocaleBaseClass.validateDateFormatStyle(timeStyle), 'Locale: TimeStyle must be one of [full/long/medium/short/none]');
return NativeLocale.dateFormat(date, dateStyle, timeStyle);
}
}
module.exports = LocaleBaseClass;