Skip to content

Commit

Permalink
Add 24 hour detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ezengsvmx committed Nov 15, 2017
1 parent 00b7875 commit 5d7a8f0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions RNDeviceInfo/RNDeviceInfo.m
Expand Up @@ -183,6 +183,12 @@ - (bool) isTablet
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
}

- (bool) is24Hour
{
NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
return ([format rangeOfString:@"a"].location == NSNotFound);
}

- (NSDictionary *)constantsToExport
{
UIDevice *currentDevice = [UIDevice currentDevice];
Expand All @@ -208,6 +214,7 @@ - (NSDictionary *)constantsToExport
@"timezone": self.timezone,
@"isEmulator": @(self.isEmulator),
@"isTablet": @(self.isTablet),
@"is24Hour": @(self.is24Hour),
};
}

Expand Down
Expand Up @@ -89,6 +89,10 @@ private Boolean isTablet() {
return layout == Configuration.SCREENLAYOUT_SIZE_LARGE || layout == Configuration.SCREENLAYOUT_SIZE_XLARGE;
}

private Boolean is24Hour() {
return android.text.format.DateFormat.is24HourFormat(this.reactContext.getApplicationContext());
}

@ReactMethod
public void isPinOrFingerprintSet(Callback callback) {
KeyguardManager keyguardManager = (KeyguardManager) this.reactContext.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); //api 16+
Expand Down Expand Up @@ -165,6 +169,7 @@ public void getMacAddress(Promise p) {
constants.put("timezone", TimeZone.getDefault().getID());
constants.put("isEmulator", this.isEmulator());
constants.put("isTablet", this.isTablet());
constants.put("is24Hour", this.is24Hour());
if (getCurrentActivity() != null &&
(getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED ||
getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED ||
Expand Down
1 change: 1 addition & 0 deletions deviceinfo.d.ts
Expand Up @@ -20,6 +20,7 @@ export function getTimezone(): string;
export function getInstanceID(): string;
export function isEmulator(): boolean;
export function isTablet(): boolean;
export function is24Hour(): boolean;
export function isPinOrFingerprintSet(): (cb: (isPinOrFingerprintSet: boolean) => void) => void;
export function getFirstInstallTime(): number;
export function getLastUpdateTime(): number;
Expand Down
3 changes: 3 additions & 0 deletions deviceinfo.js
Expand Up @@ -74,6 +74,9 @@ module.exports = {
isTablet: function() {
return RNDeviceInfo.isTablet;
},
is24Hour: function() {
return RNDeviceInfo.is24Hour;
},
isPinOrFingerprintSet: function () {
return RNDeviceInfo.isPinOrFingerprintSet;
},
Expand Down
1 change: 1 addition & 0 deletions deviceinfo.js.flow
Expand Up @@ -19,6 +19,7 @@ declare module.exports: {
getTimezone: () => string,
isEmulator: () => boolean,
isTablet: () => boolean,
is24Hour: () => boolean,
isPinOrFingerprintSet: () => (cb: (isPinOrFingerprintSet: boolean) => void) => void,
getAPILevel: () => number,
getInstanceID: () => string,
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-device-info",
"version": "0.12.1",
"version": "0.12.2",
"description": "Get device information using react-native",
"main": "deviceinfo.js",
"typings": "./deviceinfo.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions windows/RNDeviceInfo/RNDeviceInfoModule.cs
Expand Up @@ -37,6 +37,11 @@ private bool IsTablet(string os)
return !rgx.IsMatch(os);
}

private bool is24Hour()
{
return DateTimeFormatInfo.CurrentInfo.ShortTimePattern.Contains("H");
}

public override IReadOnlyDictionary<string, object> Constants
{

Expand Down Expand Up @@ -111,6 +116,7 @@ private bool IsTablet(string os)
constants["timezone"] = TimeZoneInfo.Local.Id;
constants["isEmulator"] = IsEmulator(model);
constants["isTablet"] = IsTablet(os);
constants["is24Hour"] = is24Hour();

return constants;
}
Expand Down

0 comments on commit 5d7a8f0

Please sign in to comment.