react-native-timezone 2.3.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +44 -25
- package/android/build.gradle +53 -79
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/samitha/rn/timezone/TimezoneModuleImpl.java +60 -0
- package/android/src/main/java/com/samitha/rn/timezone/TimezonePackage.java +32 -15
- package/android/src/newarch/TimezoneModule.java +9 -0
- package/android/src/oldarch/TimezoneModule.java +39 -0
- package/ios/Timezone.mm +25 -6
- package/lib/commonjs/NativeTimezone.js +9 -0
- package/lib/commonjs/NativeTimezone.js.map +1 -0
- package/lib/commonjs/index.js +16 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeTimezone.js +3 -0
- package/lib/module/NativeTimezone.js.map +1 -0
- package/lib/module/index.js +16 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeTimezone.d.ts +9 -0
- package/lib/typescript/src/NativeTimezone.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +29 -19
- package/react-native-timezone.podspec +10 -1
- package/src/NativeTimezone.ts +10 -0
- package/src/index.d.ts +4 -1
- package/src/index.tsx +36 -0
- package/android/src/main/java/com/samitha/rn/timezone/TimezoneModule.java +0 -41
- package/ios/Timezone.xcodeproj/project.pbxproj +0 -274
- package/ios/Timezone.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
- package/ios/Timezone.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/Timezone.xcodeproj/project.xcworkspace/xcuserdata/samitha.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Timezone.xcodeproj/xcuserdata/samitha.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/lib/typescript/index.test.d.ts +0 -1
- package/lib/typescript/index.test.d.ts.map +0 -1
- package/src/index.js +0 -20
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2023 Samitha Nanayakkara
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
|
6
6
|
in the Software without restriction, including without limitation the rights
|
package/README.md
CHANGED
|
@@ -1,39 +1,58 @@
|
|
|
1
|
-
# React Native Timezone
|
|
1
|
+
# React Native Timezone and Region
|
|
2
|
+
|
|
2
3
|
[](https://codeclimate.com/github/samitha9125/react-native-timezone/maintainability)
|
|
3
4
|
|
|
4
|
-
A Simple react native module to get Timezone of the Android/iOS
|
|
5
|
+
A Simple react native module to get the Timezone and the Region of the Android/iOS devices.
|
|
5
6
|
|
|
6
7
|
# Motivation
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
For a project of mine, I had to acquire the currently selected timezone of the user. Unfortunately, I could not find any react native package or react native in-build function that facilitates this. Thus I created a small library.
|
|
10
|
+
|
|
11
|
+
v3.0.0 and above, you can access the Region details. More details can be found below.
|
|
8
12
|
|
|
9
13
|
# Compatibility
|
|
10
|
-
|
|
14
|
+
|
|
15
|
+
Timezone version 3.0.0 only supports React Native version 0.62.3 and above due to the React Native Regular Expression Denial of Service (ReDoS) vulnerability.
|
|
11
16
|
|
|
12
17
|
| React native version | Tested | Result |
|
|
13
|
-
|
|
14
|
-
| 0.62.3 + |
|
|
15
|
-
| 0.
|
|
16
|
-
| 0.
|
|
18
|
+
| -------------------- | ------ | ------ |
|
|
19
|
+
| 0.62.3 + | ✅ | ✅ |
|
|
20
|
+
| 0.70.0 + | ✅ | ✅ |
|
|
21
|
+
| 0.73.0 + | ✅ | ✅ |
|
|
17
22
|
|
|
18
23
|
# Installation
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
|
|
25
|
+
`npm i react-native-timezone`
|
|
26
|
+
|
|
27
|
+
## iOS
|
|
28
|
+
|
|
29
|
+
Do `cd ios/ && pod install` or `npx pod-install`.
|
|
30
|
+
|
|
31
|
+
# Usage
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
28
34
|
import TimeZone from 'react-native-timezone';
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
export default function App() {
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
const timezone = Timezone.getTimeZone();
|
|
39
|
+
const isAutoTimeZoneEnabled = Timezone.isAutoTimeZoneEnabled();
|
|
40
|
+
const telephonyRegion = Timezone.getRegionByTelephony();
|
|
41
|
+
const localeRegion = Timezone.getRegionByLocale();
|
|
42
|
+
// Update state or use data as needed
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
// Render your component
|
|
33
46
|
}
|
|
34
47
|
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
|
|
49
|
+
Check out the [example](https://github.com/samitha9125/react-native-timezone/tree/master/example) folder.
|
|
50
|
+
|
|
51
|
+
# APIs
|
|
52
|
+
|
|
53
|
+
| API | Description |
|
|
54
|
+
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
55
|
+
| getTimeZone | Android: Returns timezone ID using `java.util.TimeZone.getID()`<br>iOS: Reflects the current system time zone using `localTimeZone` of `NSTimeZone` |
|
|
56
|
+
| isAutoTimeZoneEnabled | Returns a boolean indicating if auto timezone is enabled on the device **(Android Only)** |
|
|
57
|
+
| getRegionByTelephony | Retrieves the region information based on the telephony (SIM card) of the device. Returns `undefined` if the device has no SIM card. |
|
|
58
|
+
| getRegionByLocale | Retrieves the region information based on the device's locale settings |
|
package/android/build.gradle
CHANGED
|
@@ -1,40 +1,65 @@
|
|
|
1
1
|
buildscript {
|
|
2
2
|
repositories {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
dependencies {
|
|
8
|
-
classpath
|
|
8
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
def isNewArchitectureEnabled() {
|
|
13
|
-
return rootProject.hasProperty("newArchEnabled") &&
|
|
13
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
apply plugin:
|
|
16
|
+
apply plugin: "com.android.library"
|
|
17
17
|
|
|
18
18
|
if (isNewArchitectureEnabled()) {
|
|
19
|
-
apply plugin:
|
|
19
|
+
apply plugin: "com.facebook.react"
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
def getExtOrDefault(name) {
|
|
23
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties[
|
|
23
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Timezone_" + name]
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
def getExtOrIntegerDefault(name) {
|
|
27
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties[
|
|
27
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Timezone_" + name]).toInteger()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def supportsNamespace() {
|
|
31
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
32
|
+
def major = parsed[0].toInteger()
|
|
33
|
+
def minor = parsed[1].toInteger()
|
|
34
|
+
|
|
35
|
+
// Namespace support was added in 7.3.0
|
|
36
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
android {
|
|
31
|
-
|
|
40
|
+
if (supportsNamespace()) {
|
|
41
|
+
namespace "com.samitha.rn.timezone"
|
|
42
|
+
|
|
43
|
+
sourceSets {
|
|
44
|
+
main {
|
|
45
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
51
|
|
|
33
52
|
defaultConfig {
|
|
34
|
-
minSdkVersion getExtOrIntegerDefault(
|
|
35
|
-
targetSdkVersion getExtOrIntegerDefault(
|
|
53
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
54
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
55
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
56
|
+
|
|
37
57
|
}
|
|
58
|
+
|
|
59
|
+
buildFeatures {
|
|
60
|
+
buildConfig true
|
|
61
|
+
}
|
|
62
|
+
|
|
38
63
|
buildTypes {
|
|
39
64
|
release {
|
|
40
65
|
minifyEnabled false
|
|
@@ -42,7 +67,7 @@ android {
|
|
|
42
67
|
}
|
|
43
68
|
|
|
44
69
|
lintOptions {
|
|
45
|
-
disable
|
|
70
|
+
disable "GradleCompatible"
|
|
46
71
|
}
|
|
47
72
|
|
|
48
73
|
compileOptions {
|
|
@@ -50,83 +75,32 @@ android {
|
|
|
50
75
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
51
76
|
}
|
|
52
77
|
|
|
78
|
+
sourceSets {
|
|
79
|
+
main {
|
|
80
|
+
if (isNewArchitectureEnabled()) {
|
|
81
|
+
java.srcDirs += [
|
|
82
|
+
"src/newarch",
|
|
83
|
+
// This is needed to build Kotlin project with NewArch enabled
|
|
84
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
85
|
+
]
|
|
86
|
+
} else {
|
|
87
|
+
java.srcDirs += ["src/oldarch"]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
53
91
|
}
|
|
54
92
|
|
|
55
93
|
repositories {
|
|
56
94
|
mavenCentral()
|
|
57
95
|
google()
|
|
58
|
-
|
|
59
|
-
def found = false
|
|
60
|
-
def defaultDir = null
|
|
61
|
-
def androidSourcesName = 'React Native sources'
|
|
62
|
-
|
|
63
|
-
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
|
64
|
-
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
|
65
|
-
} else {
|
|
66
|
-
defaultDir = new File(
|
|
67
|
-
projectDir,
|
|
68
|
-
'/../../../node_modules/react-native/android'
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (defaultDir.exists()) {
|
|
73
|
-
maven {
|
|
74
|
-
url defaultDir.toString()
|
|
75
|
-
name androidSourcesName
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
|
|
79
|
-
found = true
|
|
80
|
-
} else {
|
|
81
|
-
def parentDir = rootProject.projectDir
|
|
82
|
-
|
|
83
|
-
1.upto(5, {
|
|
84
|
-
if (found) return true
|
|
85
|
-
parentDir = parentDir.parentFile
|
|
86
|
-
|
|
87
|
-
def androidSourcesDir = new File(
|
|
88
|
-
parentDir,
|
|
89
|
-
'node_modules/react-native'
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
def androidPrebuiltBinaryDir = new File(
|
|
93
|
-
parentDir,
|
|
94
|
-
'node_modules/react-native/android'
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
if (androidPrebuiltBinaryDir.exists()) {
|
|
98
|
-
maven {
|
|
99
|
-
url androidPrebuiltBinaryDir.toString()
|
|
100
|
-
name androidSourcesName
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
|
|
104
|
-
found = true
|
|
105
|
-
} else if (androidSourcesDir.exists()) {
|
|
106
|
-
maven {
|
|
107
|
-
url androidSourcesDir.toString()
|
|
108
|
-
name androidSourcesName
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
|
|
112
|
-
found = true
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!found) {
|
|
118
|
-
throw new GradleException(
|
|
119
|
-
"${project.name}: unable to locate React Native android sources. " +
|
|
120
|
-
"Ensure you have you installed React Native as a dependency in your project and try again."
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
96
|
}
|
|
124
97
|
|
|
125
98
|
|
|
126
99
|
dependencies {
|
|
127
|
-
|
|
100
|
+
// For < 0.71, this will be from the local maven repo
|
|
101
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
102
|
+
//noinspection GradleDynamicVersion
|
|
128
103
|
implementation "com.facebook.react:react-native:+"
|
|
129
|
-
// From node_modules
|
|
130
104
|
}
|
|
131
105
|
|
|
132
106
|
if (isNewArchitectureEnabled()) {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
package com.samitha.rn.timezone;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import android.os.Build;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.bridge.Promise;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
9
|
+
|
|
10
|
+
import java.util.TimeZone;
|
|
11
|
+
import java.util.Calendar;
|
|
12
|
+
import android.telephony.TelephonyManager;
|
|
13
|
+
|
|
14
|
+
import android.provider.Settings;
|
|
15
|
+
import android.content.ContentResolver;
|
|
16
|
+
import android.util.Log;
|
|
17
|
+
|
|
18
|
+
public class TimezoneModuleImpl {
|
|
19
|
+
public static final String NAME = "Timezone";
|
|
20
|
+
|
|
21
|
+
// Whether the device is set to automatically detect the time zone.
|
|
22
|
+
@ReactMethod
|
|
23
|
+
public static boolean isAutoTimeZoneEnabled(ReactApplicationContext reactContext) {
|
|
24
|
+
ContentResolver resolver = reactContext.getContentResolver();
|
|
25
|
+
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
|
|
26
|
+
? Settings.Global.getInt(resolver, Settings.Global.AUTO_TIME_ZONE, 0)
|
|
27
|
+
: Settings.System.getInt(resolver, Settings.System.AUTO_TIME_ZONE, 0)) != 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@ReactMethod
|
|
31
|
+
public static String getTimeZone() {
|
|
32
|
+
try {
|
|
33
|
+
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
|
|
34
|
+
TimeZone zone = calendar.getTimeZone();
|
|
35
|
+
return zone.getID();
|
|
36
|
+
}catch (Exception e){
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@ReactMethod
|
|
42
|
+
public static String getRegionByTelephony(ReactApplicationContext reactContext) {
|
|
43
|
+
try {
|
|
44
|
+
TelephonyManager tm = (TelephonyManager)reactContext.getSystemService(reactContext.TELEPHONY_SERVICE);
|
|
45
|
+
return tm.getNetworkCountryIso();
|
|
46
|
+
}catch (Exception e){
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ReactMethod
|
|
53
|
+
public static String getRegionByLocale(ReactApplicationContext reactContext) {
|
|
54
|
+
try {
|
|
55
|
+
return reactContext.getResources().getConfiguration().locale.getCountry();
|
|
56
|
+
}catch (Exception e){
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,28 +1,45 @@
|
|
|
1
1
|
package com.samitha.rn.timezone;
|
|
2
2
|
|
|
3
|
-
import androidx.annotation.
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
4
|
|
|
5
|
-
import com.facebook.react.ReactPackage;
|
|
6
5
|
import com.facebook.react.bridge.NativeModule;
|
|
7
6
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
-
import com.facebook.react.
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
9
|
+
import com.facebook.react.TurboReactPackage;
|
|
9
10
|
|
|
10
|
-
import java.util.
|
|
11
|
-
import java.util.
|
|
12
|
-
import java.util.List;
|
|
11
|
+
import java.util.HashMap;
|
|
12
|
+
import java.util.Map;
|
|
13
13
|
|
|
14
|
-
public class TimezonePackage
|
|
15
|
-
|
|
14
|
+
public class TimezonePackage extends TurboReactPackage {
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
16
17
|
@Override
|
|
17
|
-
public
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
|
|
19
|
+
if (name.equals(TimezoneModule.NAME)) {
|
|
20
|
+
return new TimezoneModule(reactContext);
|
|
21
|
+
} else {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
@NonNull
|
|
24
26
|
@Override
|
|
25
|
-
public
|
|
26
|
-
return
|
|
27
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
28
|
+
return () -> {
|
|
29
|
+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
|
|
30
|
+
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
|
|
31
|
+
moduleInfos.put(
|
|
32
|
+
TimezoneModule.NAME,
|
|
33
|
+
new ReactModuleInfo(
|
|
34
|
+
TimezoneModule.NAME,
|
|
35
|
+
TimezoneModule.NAME,
|
|
36
|
+
false, // canOverrideExistingModule
|
|
37
|
+
false, // needsEagerInit
|
|
38
|
+
true, // hasConstants
|
|
39
|
+
false, // isCxxModule
|
|
40
|
+
isTurboModule // isTurboModule
|
|
41
|
+
));
|
|
42
|
+
return moduleInfos;
|
|
43
|
+
};
|
|
27
44
|
}
|
|
28
45
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package com.samitha.rn.timezone;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
8
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
9
|
+
|
|
10
|
+
public class TimezoneModule extends ReactContextBaseJavaModule {
|
|
11
|
+
public static final String NAME = TimezoneModuleImpl.NAME;
|
|
12
|
+
|
|
13
|
+
TimezoneModule(ReactApplicationContext context) {
|
|
14
|
+
super(context);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Override
|
|
18
|
+
@NonNull
|
|
19
|
+
public String getName() {
|
|
20
|
+
return TimezoneModuleImpl.NAME;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
24
|
+
public boolean isAutoTimeZoneEnabled() {
|
|
25
|
+
return TimezoneModuleImpl.isAutoTimeZoneEnabled(getReactApplicationContext());
|
|
26
|
+
}
|
|
27
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
28
|
+
public String getTimeZone() {
|
|
29
|
+
return TimezoneModuleImpl.getTimeZone();
|
|
30
|
+
}
|
|
31
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
32
|
+
public String getRegionByTelephony() {
|
|
33
|
+
return TimezoneModuleImpl.getRegionByTelephony(getReactApplicationContext());
|
|
34
|
+
}
|
|
35
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
36
|
+
public String getRegionByLocale() {
|
|
37
|
+
return TimezoneModuleImpl.getRegionByLocale(getReactApplicationContext());
|
|
38
|
+
}
|
|
39
|
+
}
|
package/ios/Timezone.mm
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
|
+
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
|
|
2
|
+
#import <CoreTelephony/CTCarrier.h>
|
|
1
3
|
#import "Timezone.h"
|
|
2
4
|
|
|
3
5
|
@implementation Timezone
|
|
4
6
|
RCT_EXPORT_MODULE()
|
|
5
7
|
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
RCT_REMAP_METHOD(getTimeZone,
|
|
9
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
10
|
-
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
8
|
+
// Get the current timezone using NSTimeZone
|
|
9
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getTimeZone)
|
|
11
10
|
{
|
|
12
11
|
NSTimeZone *timeZone = [NSTimeZone localTimeZone];
|
|
13
|
-
|
|
12
|
+
return timeZone.name;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Get the current timezone using CTTelephonyNetworkInfo
|
|
16
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getRegionByTelephony)
|
|
17
|
+
{
|
|
18
|
+
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
|
|
19
|
+
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
|
|
20
|
+
NSString *isoCountryCode = [carrier isoCountryCode];
|
|
21
|
+
if (isoCountryCode == nil || [isoCountryCode isEqualToString:@""]) {
|
|
22
|
+
return nil;
|
|
23
|
+
}
|
|
24
|
+
return isoCountryCode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Get the current timezone using NSLocale
|
|
28
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getRegionByLocale)
|
|
29
|
+
{
|
|
30
|
+
NSLocale *locale = [NSLocale currentLocale];
|
|
31
|
+
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
|
|
32
|
+
return countryCode;
|
|
14
33
|
}
|
|
15
34
|
|
|
16
35
|
// Don't compile this code when we build for the old architecture.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('Timezone');
|
|
9
|
+
//# sourceMappingURL=NativeTimezone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeTimezone.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAQpCC,gCAAmB,CAACC,YAAY,CAAO,UAAU,CAAC"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -9,11 +9,24 @@ const LINKING_ERROR = `The package 'react-native-timezone' doesn't seem to be li
|
|
|
9
9
|
ios: "- You have run 'pod install'\n",
|
|
10
10
|
default: ''
|
|
11
11
|
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
15
|
+
const TimezoneModule = isTurboModuleEnabled ? require('./NativeTimezone').default : _reactNative.NativeModules.Timezone;
|
|
16
|
+
const Timezone = TimezoneModule ? TimezoneModule : new Proxy({}, {
|
|
13
17
|
get() {
|
|
14
18
|
throw new Error(LINKING_ERROR);
|
|
15
19
|
}
|
|
16
20
|
});
|
|
17
|
-
var _default =
|
|
18
|
-
|
|
21
|
+
var _default = exports.default = {
|
|
22
|
+
getTimeZone: () => Timezone.getTimeZone(),
|
|
23
|
+
getRegionByLocale: () => Timezone.getRegionByLocale(),
|
|
24
|
+
getRegionByTelephony: () => Timezone.getRegionByTelephony() ?? undefined,
|
|
25
|
+
isAutoTimeZoneEnabled: () => {
|
|
26
|
+
if (_reactNative.Platform.OS === 'android') {
|
|
27
|
+
return Timezone.isAutoTimeZoneEnabled();
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
19
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","TimezoneModule","NativeModules","Timezone","Proxy","get","Error","_default","exports","getTimeZone","getRegionByLocale","getRegionByTelephony","undefined","isAutoTimeZoneEnabled","OS"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GAChB,gFAA+E,GAChFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAC9D,MAAMC,cAAc,GAAGH,oBAAoB,GACvCN,OAAO,CAAC,kBAAkB,CAAC,CAACK,OAAO,GACnCK,0BAAa,CAACC,QAAQ;AAE1B,MAAMA,QAAQ,GAAGF,cAAc,GAC3BA,cAAc,GACd,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACb,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAAC,IAAAc,QAAA,GAAAC,OAAA,CAAAX,OAAA,GAES;EACbY,WAAW,EAAEA,CAAA,KAAMN,QAAQ,CAACM,WAAW,CAAC,CAAC;EACzCC,iBAAiB,EAAEA,CAAA,KAAMP,QAAQ,CAACO,iBAAiB,CAAC,CAAC;EACrDC,oBAAoB,EAAEA,CAAA,KAAMR,QAAQ,CAACQ,oBAAoB,CAAC,CAAC,IAAIC,SAAS;EACxEC,qBAAqB,EAAEA,CAAA,KAAM;IAC3B,IAAInB,qBAAQ,CAACoB,EAAE,KAAK,SAAS,EAAE;MAC7B,OAAOX,QAAQ,CAACU,qBAAqB,CAAC,CAAC;IACzC;IACA,OAAOD,SAAS;EAClB;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeTimezone.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAQlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,UAAU,CAAC"}
|
package/lib/module/index.js
CHANGED
|
@@ -3,10 +3,24 @@ const LINKING_ERROR = `The package 'react-native-timezone' doesn't seem to be li
|
|
|
3
3
|
ios: "- You have run 'pod install'\n",
|
|
4
4
|
default: ''
|
|
5
5
|
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
9
|
+
const TimezoneModule = isTurboModuleEnabled ? require('./NativeTimezone').default : NativeModules.Timezone;
|
|
10
|
+
const Timezone = TimezoneModule ? TimezoneModule : new Proxy({}, {
|
|
7
11
|
get() {
|
|
8
12
|
throw new Error(LINKING_ERROR);
|
|
9
13
|
}
|
|
10
14
|
});
|
|
11
|
-
export default
|
|
15
|
+
export default {
|
|
16
|
+
getTimeZone: () => Timezone.getTimeZone(),
|
|
17
|
+
getRegionByLocale: () => Timezone.getRegionByLocale(),
|
|
18
|
+
getRegionByTelephony: () => Timezone.getRegionByTelephony() ?? undefined,
|
|
19
|
+
isAutoTimeZoneEnabled: () => {
|
|
20
|
+
if (Platform.OS === 'android') {
|
|
21
|
+
return Timezone.isAutoTimeZoneEnabled();
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
12
26
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","Timezone","Proxy","get","Error"],"sourceRoot":"../../src","sources":["index.
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","TimezoneModule","require","Timezone","Proxy","get","Error","getTimeZone","getRegionByLocale","getRegionByTelephony","undefined","isAutoTimeZoneEnabled","OS"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GAChB,gFAA+E,GAChFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAC9D,MAAMC,cAAc,GAAGH,oBAAoB,GACvCI,OAAO,CAAC,kBAAkB,CAAC,CAACL,OAAO,GACnCL,aAAa,CAACW,QAAQ;AAE1B,MAAMA,QAAQ,GAAGF,cAAc,GAC3BA,cAAc,GACd,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACZ,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,eAAe;EACba,WAAW,EAAEA,CAAA,KAAMJ,QAAQ,CAACI,WAAW,CAAC,CAAC;EACzCC,iBAAiB,EAAEA,CAAA,KAAML,QAAQ,CAACK,iBAAiB,CAAC,CAAC;EACrDC,oBAAoB,EAAEA,CAAA,KAAMN,QAAQ,CAACM,oBAAoB,CAAC,CAAC,IAAIC,SAAS;EACxEC,qBAAqB,EAAEA,CAAA,KAAM;IAC3B,IAAIlB,QAAQ,CAACmB,EAAE,KAAK,SAAS,EAAE;MAC7B,OAAOT,QAAQ,CAACQ,qBAAqB,CAAC,CAAC;IACzC;IACA,OAAOD,SAAS;EAClB;AACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
export interface Spec extends TurboModule {
|
|
3
|
+
getTimeZone(): string;
|
|
4
|
+
getRegionByLocale(): string;
|
|
5
|
+
getRegionByTelephony(): string;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: Spec;
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=NativeTimezone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeTimezone.d.ts","sourceRoot":"","sources":["../../../src/NativeTimezone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,WAAW,IAAI,MAAM,CAAC;IACtB,iBAAiB,IAAI,MAAM,CAAC;IAC5B,oBAAoB,IAAI,MAAM,CAAC;CAChC;;AAED,wBAAkE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":";;;;;;AAyBA,wBAUE"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-timezone",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A Simple react native module to get Timezone of the Android/iOS
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "A Simple react native module to get Timezone and Region of the Android/iOS devices.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
7
|
-
"types": "lib/typescript/index.d.ts",
|
|
7
|
+
"types": "lib/typescript/src/index.d.ts",
|
|
8
8
|
"react-native": "src/index",
|
|
9
9
|
"source": "src/index",
|
|
10
10
|
"files": [
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"ios",
|
|
15
15
|
"cpp",
|
|
16
16
|
"*.podspec",
|
|
17
|
-
"!lib/typescript/example",
|
|
18
17
|
"!ios/build",
|
|
19
18
|
"!android/build",
|
|
20
19
|
"!android/gradle",
|
|
@@ -27,22 +26,24 @@
|
|
|
27
26
|
"!**/.*"
|
|
28
27
|
],
|
|
29
28
|
"scripts": {
|
|
29
|
+
"example": "yarn workspace react-native-timezone-example",
|
|
30
30
|
"test": "jest",
|
|
31
|
-
"
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
32
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
33
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
33
34
|
"prepare": "bob build",
|
|
34
|
-
"release": "release-it"
|
|
35
|
-
"example": "yarn --cwd example",
|
|
36
|
-
"bootstrap": "yarn example && yarn install && yarn example pods",
|
|
37
|
-
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
|
|
35
|
+
"release": "release-it"
|
|
38
36
|
},
|
|
39
37
|
"keywords": [
|
|
40
38
|
"react-native",
|
|
41
39
|
"ios",
|
|
42
40
|
"android"
|
|
43
41
|
],
|
|
44
|
-
"repository":
|
|
45
|
-
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/samitha9125/react-native-timezone.git"
|
|
45
|
+
},
|
|
46
|
+
"author": "Samitha Nanayakkara <samithananayakkara@gmail.com> (https://samithananayakkara.com)",
|
|
46
47
|
"license": "MIT",
|
|
47
48
|
"bugs": {
|
|
48
49
|
"url": "https://github.com/samitha9125/react-native-timezone/issues"
|
|
@@ -52,9 +53,9 @@
|
|
|
52
53
|
"registry": "https://registry.npmjs.org/"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@arkweid/lefthook": "^0.7.7",
|
|
56
56
|
"@commitlint/config-conventional": "^17.0.2",
|
|
57
|
-
"@
|
|
57
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
58
|
+
"@react-native/eslint-config": "^0.72.2",
|
|
58
59
|
"@release-it/conventional-changelog": "^5.0.0",
|
|
59
60
|
"@types/jest": "^28.1.2",
|
|
60
61
|
"@types/react": "~17.0.21",
|
|
@@ -67,11 +68,12 @@
|
|
|
67
68
|
"jest": "^28.1.1",
|
|
68
69
|
"pod-install": "^0.1.0",
|
|
69
70
|
"prettier": "^2.0.5",
|
|
70
|
-
"react": "18.
|
|
71
|
-
"react-native": "0.
|
|
71
|
+
"react": "18.2.0",
|
|
72
|
+
"react-native": "0.73.0",
|
|
72
73
|
"react-native-builder-bob": "^0.20.0",
|
|
73
74
|
"release-it": "^15.0.0",
|
|
74
|
-
"
|
|
75
|
+
"turbo": "^1.10.7",
|
|
76
|
+
"typescript": "^5.0.2"
|
|
75
77
|
},
|
|
76
78
|
"resolutions": {
|
|
77
79
|
"@types/react": "17.0.21"
|
|
@@ -80,10 +82,13 @@
|
|
|
80
82
|
"react": "*",
|
|
81
83
|
"react-native": "*"
|
|
82
84
|
},
|
|
85
|
+
"workspaces": [
|
|
86
|
+
"example"
|
|
87
|
+
],
|
|
88
|
+
"packageManager": "yarn@3.6.1",
|
|
83
89
|
"engines": {
|
|
84
|
-
"node": ">=
|
|
90
|
+
"node": ">= 18.0.0"
|
|
85
91
|
},
|
|
86
|
-
"packageManager": "^yarn@1.22.15",
|
|
87
92
|
"jest": {
|
|
88
93
|
"preset": "react-native",
|
|
89
94
|
"modulePathIgnorePatterns": [
|
|
@@ -116,7 +121,7 @@
|
|
|
116
121
|
"eslintConfig": {
|
|
117
122
|
"root": true,
|
|
118
123
|
"extends": [
|
|
119
|
-
"@react-native
|
|
124
|
+
"@react-native",
|
|
120
125
|
"prettier"
|
|
121
126
|
],
|
|
122
127
|
"rules": {
|
|
@@ -156,5 +161,10 @@
|
|
|
156
161
|
}
|
|
157
162
|
]
|
|
158
163
|
]
|
|
164
|
+
},
|
|
165
|
+
"codegenConfig": {
|
|
166
|
+
"name": "RNTimezoneSpec",
|
|
167
|
+
"type": "modules",
|
|
168
|
+
"jsSrcsDir": "src"
|
|
159
169
|
}
|
|
160
170
|
}
|
|
@@ -14,8 +14,16 @@ Pod::Spec.new do |s|
|
|
|
14
14
|
s.platforms = { :ios => "11.0" }
|
|
15
15
|
s.source = { :git => "https://github.com/samitha9125/react-native-timezone.git", :tag => "#{s.version}" }
|
|
16
16
|
|
|
17
|
+
# Frameworks to include in the project.
|
|
18
|
+
s.frameworks = 'CoreTelephony'
|
|
19
|
+
|
|
17
20
|
s.source_files = "ios/**/*.{h,m,mm}"
|
|
18
21
|
|
|
22
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
23
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
24
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
25
|
+
install_modules_dependencies(s)
|
|
26
|
+
else
|
|
19
27
|
s.dependency "React-Core"
|
|
20
28
|
|
|
21
29
|
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
@@ -31,5 +39,6 @@ Pod::Spec.new do |s|
|
|
|
31
39
|
s.dependency "RCTRequired"
|
|
32
40
|
s.dependency "RCTTypeSafety"
|
|
33
41
|
s.dependency "ReactCommon/turbomodule/core"
|
|
34
|
-
|
|
42
|
+
end
|
|
43
|
+
end
|
|
35
44
|
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
getTimeZone(): string;
|
|
6
|
+
getRegionByLocale(): string;
|
|
7
|
+
getRegionByTelephony(): string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('Timezone');
|
package/src/index.d.ts
CHANGED
package/src/index.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package 'react-native-timezone' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
+
'- You rebuilt the app after installing the package\n' +
|
|
7
|
+
'- You are not using Expo Go\n';
|
|
8
|
+
|
|
9
|
+
// @ts-expect-error
|
|
10
|
+
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
11
|
+
const TimezoneModule = isTurboModuleEnabled
|
|
12
|
+
? require('./NativeTimezone').default
|
|
13
|
+
: NativeModules.Timezone;
|
|
14
|
+
|
|
15
|
+
const Timezone = TimezoneModule
|
|
16
|
+
? TimezoneModule
|
|
17
|
+
: new Proxy(
|
|
18
|
+
{},
|
|
19
|
+
{
|
|
20
|
+
get() {
|
|
21
|
+
throw new Error(LINKING_ERROR);
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
getTimeZone: () => Timezone.getTimeZone(),
|
|
28
|
+
getRegionByLocale: () => Timezone.getRegionByLocale(),
|
|
29
|
+
getRegionByTelephony: () => Timezone.getRegionByTelephony() ?? undefined,
|
|
30
|
+
isAutoTimeZoneEnabled: () => {
|
|
31
|
+
if (Platform.OS === 'android') {
|
|
32
|
+
return Timezone.isAutoTimeZoneEnabled();
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
package com.samitha.rn.timezone;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.Promise;
|
|
6
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
8
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
9
|
-
import com.facebook.react.module.annotations.ReactModule;
|
|
10
|
-
|
|
11
|
-
import java.util.TimeZone;
|
|
12
|
-
import java.util.Calendar;
|
|
13
|
-
|
|
14
|
-
@ReactModule(name = TimezoneModule.NAME)
|
|
15
|
-
public class TimezoneModule extends ReactContextBaseJavaModule {
|
|
16
|
-
public static final String NAME = "Timezone";
|
|
17
|
-
|
|
18
|
-
public TimezoneModule(ReactApplicationContext reactContext) {
|
|
19
|
-
super(reactContext);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Override
|
|
23
|
-
@NonNull
|
|
24
|
-
public String getName() {
|
|
25
|
-
return NAME;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// Example method
|
|
30
|
-
// See https://reactnative.dev/docs/native-modules-android
|
|
31
|
-
@ReactMethod
|
|
32
|
-
public void getTimeZone(Promise promise) {
|
|
33
|
-
try {
|
|
34
|
-
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
|
|
35
|
-
TimeZone zone = calendar.getTimeZone();
|
|
36
|
-
promise.resolve(zone.getID());
|
|
37
|
-
}catch (Exception e){
|
|
38
|
-
promise.reject(e);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
// !$*UTF8*$!
|
|
2
|
-
{
|
|
3
|
-
archiveVersion = 1;
|
|
4
|
-
classes = {
|
|
5
|
-
};
|
|
6
|
-
objectVersion = 46;
|
|
7
|
-
objects = {
|
|
8
|
-
|
|
9
|
-
/* Begin PBXBuildFile section */
|
|
10
|
-
5E555C0D2413F4C50049A1A2 /* Timezone.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* Timezone.m */; };
|
|
11
|
-
/* End PBXBuildFile section */
|
|
12
|
-
|
|
13
|
-
/* Begin PBXCopyFilesBuildPhase section */
|
|
14
|
-
58B511D91A9E6C8500147676 /* CopyFiles */ = {
|
|
15
|
-
isa = PBXCopyFilesBuildPhase;
|
|
16
|
-
buildActionMask = 2147483647;
|
|
17
|
-
dstPath = "include/$(PRODUCT_NAME)";
|
|
18
|
-
dstSubfolderSpec = 16;
|
|
19
|
-
files = (
|
|
20
|
-
);
|
|
21
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
22
|
-
};
|
|
23
|
-
/* End PBXCopyFilesBuildPhase section */
|
|
24
|
-
|
|
25
|
-
/* Begin PBXFileReference section */
|
|
26
|
-
134814201AA4EA6300B7C361 /* libTimezone.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libTimezone.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
27
|
-
B3E7B5881CC2AC0600A0062D /* Timezone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Timezone.h; sourceTree = "<group>"; };
|
|
28
|
-
B3E7B5891CC2AC0600A0062D /* Timezone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Timezone.m; sourceTree = "<group>"; };
|
|
29
|
-
/* End PBXFileReference section */
|
|
30
|
-
|
|
31
|
-
/* Begin PBXFrameworksBuildPhase section */
|
|
32
|
-
58B511D81A9E6C8500147676 /* Frameworks */ = {
|
|
33
|
-
isa = PBXFrameworksBuildPhase;
|
|
34
|
-
buildActionMask = 2147483647;
|
|
35
|
-
files = (
|
|
36
|
-
);
|
|
37
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
38
|
-
};
|
|
39
|
-
/* End PBXFrameworksBuildPhase section */
|
|
40
|
-
|
|
41
|
-
/* Begin PBXGroup section */
|
|
42
|
-
134814211AA4EA7D00B7C361 /* Products */ = {
|
|
43
|
-
isa = PBXGroup;
|
|
44
|
-
children = (
|
|
45
|
-
134814201AA4EA6300B7C361 /* libTimezone.a */,
|
|
46
|
-
);
|
|
47
|
-
name = Products;
|
|
48
|
-
sourceTree = "<group>";
|
|
49
|
-
};
|
|
50
|
-
58B511D21A9E6C8500147676 = {
|
|
51
|
-
isa = PBXGroup;
|
|
52
|
-
children = (
|
|
53
|
-
B3E7B5881CC2AC0600A0062D /* Timezone.h */,
|
|
54
|
-
B3E7B5891CC2AC0600A0062D /* Timezone.m */,
|
|
55
|
-
134814211AA4EA7D00B7C361 /* Products */,
|
|
56
|
-
);
|
|
57
|
-
sourceTree = "<group>";
|
|
58
|
-
};
|
|
59
|
-
/* End PBXGroup section */
|
|
60
|
-
|
|
61
|
-
/* Begin PBXNativeTarget section */
|
|
62
|
-
58B511DA1A9E6C8500147676 /* Timezone */ = {
|
|
63
|
-
isa = PBXNativeTarget;
|
|
64
|
-
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Timezone" */;
|
|
65
|
-
buildPhases = (
|
|
66
|
-
58B511D71A9E6C8500147676 /* Sources */,
|
|
67
|
-
58B511D81A9E6C8500147676 /* Frameworks */,
|
|
68
|
-
58B511D91A9E6C8500147676 /* CopyFiles */,
|
|
69
|
-
);
|
|
70
|
-
buildRules = (
|
|
71
|
-
);
|
|
72
|
-
dependencies = (
|
|
73
|
-
);
|
|
74
|
-
name = Timezone;
|
|
75
|
-
productName = RCTDataManager;
|
|
76
|
-
productReference = 134814201AA4EA6300B7C361 /* libTimezone.a */;
|
|
77
|
-
productType = "com.apple.product-type.library.static";
|
|
78
|
-
};
|
|
79
|
-
/* End PBXNativeTarget section */
|
|
80
|
-
|
|
81
|
-
/* Begin PBXProject section */
|
|
82
|
-
58B511D31A9E6C8500147676 /* Project object */ = {
|
|
83
|
-
isa = PBXProject;
|
|
84
|
-
attributes = {
|
|
85
|
-
LastUpgradeCheck = 0920;
|
|
86
|
-
ORGANIZATIONNAME = Facebook;
|
|
87
|
-
TargetAttributes = {
|
|
88
|
-
58B511DA1A9E6C8500147676 = {
|
|
89
|
-
CreatedOnToolsVersion = 6.1.1;
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Timezone" */;
|
|
94
|
-
compatibilityVersion = "Xcode 3.2";
|
|
95
|
-
developmentRegion = English;
|
|
96
|
-
hasScannedForEncodings = 0;
|
|
97
|
-
knownRegions = (
|
|
98
|
-
English,
|
|
99
|
-
en,
|
|
100
|
-
);
|
|
101
|
-
mainGroup = 58B511D21A9E6C8500147676;
|
|
102
|
-
productRefGroup = 58B511D21A9E6C8500147676;
|
|
103
|
-
projectDirPath = "";
|
|
104
|
-
projectRoot = "";
|
|
105
|
-
targets = (
|
|
106
|
-
58B511DA1A9E6C8500147676 /* Timezone */,
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
/* End PBXProject section */
|
|
110
|
-
|
|
111
|
-
/* Begin PBXSourcesBuildPhase section */
|
|
112
|
-
58B511D71A9E6C8500147676 /* Sources */ = {
|
|
113
|
-
isa = PBXSourcesBuildPhase;
|
|
114
|
-
buildActionMask = 2147483647;
|
|
115
|
-
files = (
|
|
116
|
-
B3E7B58A1CC2AC0600A0062D /* Timezone.m in Sources */,
|
|
117
|
-
);
|
|
118
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
119
|
-
};
|
|
120
|
-
/* End PBXSourcesBuildPhase section */
|
|
121
|
-
|
|
122
|
-
/* Begin XCBuildConfiguration section */
|
|
123
|
-
58B511ED1A9E6C8500147676 /* Debug */ = {
|
|
124
|
-
isa = XCBuildConfiguration;
|
|
125
|
-
buildSettings = {
|
|
126
|
-
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
127
|
-
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
|
128
|
-
CLANG_CXX_LIBRARY = "libc++";
|
|
129
|
-
CLANG_ENABLE_MODULES = YES;
|
|
130
|
-
CLANG_ENABLE_OBJC_ARC = YES;
|
|
131
|
-
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
|
132
|
-
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
133
|
-
CLANG_WARN_COMMA = YES;
|
|
134
|
-
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
135
|
-
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
136
|
-
CLANG_WARN_EMPTY_BODY = YES;
|
|
137
|
-
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
138
|
-
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
139
|
-
CLANG_WARN_INT_CONVERSION = YES;
|
|
140
|
-
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
141
|
-
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
142
|
-
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
143
|
-
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
144
|
-
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
|
145
|
-
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
|
146
|
-
CLANG_WARN_UNREACHABLE_CODE = YES;
|
|
147
|
-
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
|
148
|
-
COPY_PHASE_STRIP = NO;
|
|
149
|
-
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
150
|
-
ENABLE_TESTABILITY = YES;
|
|
151
|
-
"EXCLUDED_ARCHS[sdk=*]" = arm64;
|
|
152
|
-
GCC_C_LANGUAGE_STANDARD = gnu99;
|
|
153
|
-
GCC_DYNAMIC_NO_PIC = NO;
|
|
154
|
-
GCC_NO_COMMON_BLOCKS = YES;
|
|
155
|
-
GCC_OPTIMIZATION_LEVEL = 0;
|
|
156
|
-
GCC_PREPROCESSOR_DEFINITIONS = (
|
|
157
|
-
"DEBUG=1",
|
|
158
|
-
"$(inherited)",
|
|
159
|
-
);
|
|
160
|
-
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
|
161
|
-
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
|
162
|
-
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
|
163
|
-
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
|
164
|
-
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
165
|
-
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
166
|
-
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
167
|
-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
|
168
|
-
MTL_ENABLE_DEBUG_INFO = YES;
|
|
169
|
-
ONLY_ACTIVE_ARCH = YES;
|
|
170
|
-
SDKROOT = iphoneos;
|
|
171
|
-
};
|
|
172
|
-
name = Debug;
|
|
173
|
-
};
|
|
174
|
-
58B511EE1A9E6C8500147676 /* Release */ = {
|
|
175
|
-
isa = XCBuildConfiguration;
|
|
176
|
-
buildSettings = {
|
|
177
|
-
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
178
|
-
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
|
179
|
-
CLANG_CXX_LIBRARY = "libc++";
|
|
180
|
-
CLANG_ENABLE_MODULES = YES;
|
|
181
|
-
CLANG_ENABLE_OBJC_ARC = YES;
|
|
182
|
-
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
|
183
|
-
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
184
|
-
CLANG_WARN_COMMA = YES;
|
|
185
|
-
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
186
|
-
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
187
|
-
CLANG_WARN_EMPTY_BODY = YES;
|
|
188
|
-
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
189
|
-
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
190
|
-
CLANG_WARN_INT_CONVERSION = YES;
|
|
191
|
-
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
192
|
-
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
193
|
-
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
194
|
-
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
195
|
-
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
|
196
|
-
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
|
197
|
-
CLANG_WARN_UNREACHABLE_CODE = YES;
|
|
198
|
-
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
|
199
|
-
COPY_PHASE_STRIP = YES;
|
|
200
|
-
ENABLE_NS_ASSERTIONS = NO;
|
|
201
|
-
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
202
|
-
"EXCLUDED_ARCHS[sdk=*]" = arm64;
|
|
203
|
-
GCC_C_LANGUAGE_STANDARD = gnu99;
|
|
204
|
-
GCC_NO_COMMON_BLOCKS = YES;
|
|
205
|
-
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
|
206
|
-
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
|
207
|
-
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
|
208
|
-
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
209
|
-
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
210
|
-
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
211
|
-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
|
212
|
-
MTL_ENABLE_DEBUG_INFO = NO;
|
|
213
|
-
SDKROOT = iphoneos;
|
|
214
|
-
VALIDATE_PRODUCT = YES;
|
|
215
|
-
};
|
|
216
|
-
name = Release;
|
|
217
|
-
};
|
|
218
|
-
58B511F01A9E6C8500147676 /* Debug */ = {
|
|
219
|
-
isa = XCBuildConfiguration;
|
|
220
|
-
buildSettings = {
|
|
221
|
-
HEADER_SEARCH_PATHS = (
|
|
222
|
-
"$(inherited)",
|
|
223
|
-
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
|
224
|
-
"$(SRCROOT)/../../../React/**",
|
|
225
|
-
"$(SRCROOT)/../../react-native/React/**",
|
|
226
|
-
);
|
|
227
|
-
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
|
228
|
-
OTHER_LDFLAGS = "-ObjC";
|
|
229
|
-
PRODUCT_NAME = Timezone;
|
|
230
|
-
SKIP_INSTALL = YES;
|
|
231
|
-
};
|
|
232
|
-
name = Debug;
|
|
233
|
-
};
|
|
234
|
-
58B511F11A9E6C8500147676 /* Release */ = {
|
|
235
|
-
isa = XCBuildConfiguration;
|
|
236
|
-
buildSettings = {
|
|
237
|
-
HEADER_SEARCH_PATHS = (
|
|
238
|
-
"$(inherited)",
|
|
239
|
-
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
|
240
|
-
"$(SRCROOT)/../../../React/**",
|
|
241
|
-
"$(SRCROOT)/../../react-native/React/**",
|
|
242
|
-
);
|
|
243
|
-
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
|
244
|
-
OTHER_LDFLAGS = "-ObjC";
|
|
245
|
-
PRODUCT_NAME = Timezone;
|
|
246
|
-
SKIP_INSTALL = YES;
|
|
247
|
-
};
|
|
248
|
-
name = Release;
|
|
249
|
-
};
|
|
250
|
-
/* End XCBuildConfiguration section */
|
|
251
|
-
|
|
252
|
-
/* Begin XCConfigurationList section */
|
|
253
|
-
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Timezone" */ = {
|
|
254
|
-
isa = XCConfigurationList;
|
|
255
|
-
buildConfigurations = (
|
|
256
|
-
58B511ED1A9E6C8500147676 /* Debug */,
|
|
257
|
-
58B511EE1A9E6C8500147676 /* Release */,
|
|
258
|
-
);
|
|
259
|
-
defaultConfigurationIsVisible = 0;
|
|
260
|
-
defaultConfigurationName = Release;
|
|
261
|
-
};
|
|
262
|
-
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Timezone" */ = {
|
|
263
|
-
isa = XCConfigurationList;
|
|
264
|
-
buildConfigurations = (
|
|
265
|
-
58B511F01A9E6C8500147676 /* Debug */,
|
|
266
|
-
58B511F11A9E6C8500147676 /* Release */,
|
|
267
|
-
);
|
|
268
|
-
defaultConfigurationIsVisible = 0;
|
|
269
|
-
defaultConfigurationName = Release;
|
|
270
|
-
};
|
|
271
|
-
/* End XCConfigurationList section */
|
|
272
|
-
};
|
|
273
|
-
rootObject = 58B511D31A9E6C8500147676 /* Project object */;
|
|
274
|
-
}
|
|
Binary file
|
package/ios/Timezone.xcodeproj/xcuserdata/samitha.xcuserdatad/xcschemes/xcschememanagement.plist
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>SchemeUserState</key>
|
|
6
|
-
<dict>
|
|
7
|
-
<key>Timezone.xcscheme_^#shared#^_</key>
|
|
8
|
-
<dict>
|
|
9
|
-
<key>orderHint</key>
|
|
10
|
-
<integer>0</integer>
|
|
11
|
-
</dict>
|
|
12
|
-
</dict>
|
|
13
|
-
</dict>
|
|
14
|
-
</plist>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=index.test.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/index.test.tsx"],"names":[],"mappings":""}
|
package/src/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { NativeModules, Platform } from 'react-native';
|
|
2
|
-
|
|
3
|
-
const LINKING_ERROR =
|
|
4
|
-
`The package 'react-native-timezone' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
-
'- You rebuilt the app after installing the package\n' +
|
|
7
|
-
'- You are not using Expo Go\n';
|
|
8
|
-
|
|
9
|
-
const Timezone = NativeModules.Timezone
|
|
10
|
-
? NativeModules.Timezone
|
|
11
|
-
: new Proxy(
|
|
12
|
-
{},
|
|
13
|
-
{
|
|
14
|
-
get() {
|
|
15
|
-
throw new Error(LINKING_ERROR);
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
export default Timezone;
|