@greatdayhr/capacitor-datetime-setting 1.0.1 → 1.1.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.
@@ -3,7 +3,7 @@ require 'json'
3
3
  package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
4
 
5
5
  Pod::Spec.new do |s|
6
- s.name = 'CapacitorDatetimeSetting'
6
+ s.name = 'GreatdayhrCapacitorDatetimeSetting'
7
7
  s.version = package['version']
8
8
  s.summary = package['description']
9
9
  s.license = package['license']
package/README.md CHANGED
@@ -20,8 +20,8 @@ Check if automatic time is enabled on the device.
20
20
  **Returns:** `Promise<{ value: boolean }>`
21
21
 
22
22
  **Platform Support:**
23
- - ✅ Android: Returns actual setting value
24
- - ⚠️ iOS: Always returns `false` (iOS doesn't provide API to check this)
23
+ - ✅ Android: Returns actual setting value using `Settings.Global.AUTO_TIME`
24
+ - iOS: Returns actual setting value using `NSTimeZone.autoupdatingCurrent` comparison
25
25
 
26
26
  **Example:**
27
27
 
@@ -41,8 +41,8 @@ Check if automatic timezone is enabled on the device.
41
41
  **Returns:** `Promise<{ value: boolean }>`
42
42
 
43
43
  **Platform Support:**
44
- - ✅ Android: Returns actual setting value
45
- - ⚠️ iOS: Always returns `false` (iOS doesn't provide API to check this)
44
+ - ✅ Android: Returns actual setting value using `Settings.Global.AUTO_TIME_ZONE`
45
+ - iOS: Returns actual setting value using `NSTimeZone.autoupdatingCurrent` comparison
46
46
 
47
47
  **Example:**
48
48
 
@@ -88,21 +88,11 @@ async function checkAutoTimeSettings() {
88
88
 
89
89
  const platform = Capacitor.getPlatform();
90
90
 
91
- if (platform === 'android') {
92
- if (!timeResult.value || !timezoneResult.value) {
93
- // Show alert to user
94
- const shouldOpen = confirm(
95
- 'Please enable automatic date & time and timezone for accurate time tracking.'
96
- );
97
-
98
- if (shouldOpen) {
99
- await DateTimeSetting.openSetting();
100
- }
101
- }
102
- } else if (platform === 'ios') {
103
- // iOS doesn't provide API to check, so we can only prompt user to check manually
91
+ // Both Android and iOS can now detect auto time settings
92
+ if (!timeResult.value || !timezoneResult.value) {
93
+ // Show alert to user
104
94
  const shouldOpen = confirm(
105
- 'Please ensure automatic date & time is enabled in Settings.'
95
+ 'Please enable automatic date & time and timezone for accurate time tracking.'
106
96
  );
107
97
 
108
98
  if (shouldOpen) {
@@ -125,16 +115,18 @@ The plugin uses Android's `Settings.Global` API to check the auto time and timez
125
115
 
126
116
  ### iOS
127
117
 
128
- iOS does not provide public APIs to:
129
- - Check if automatic date & time is enabled
130
- - Check if automatic timezone is enabled
131
- - Open the Date & Time settings page directly
118
+ iOS does not provide direct public APIs to check auto date/time settings, but this plugin uses a **workaround** technique:
119
+
120
+ **Detection Method:**
121
+ - Compares `NSTimeZone.autoupdatingCurrent` with `NSTimeZone.system`
122
+ - When auto date/time is **enabled**: these two timezone objects are equal
123
+ - When auto date/time is **disabled**: they may differ
132
124
 
133
- Therefore:
134
- - `timeIsAuto()` and `timeZoneIsAuto()` always return `false`
135
- - `openSetting()` opens the main Settings app instead of the specific Date & Time page
125
+ **Limitations:**
126
+ - `openSetting()` opens the main Settings app instead of the specific Date & Time page (iOS restriction)
127
+ - The detection method is a workaround and may not be 100% accurate in all edge cases
136
128
 
137
- This is a platform limitation, not a plugin limitation.
129
+ **Credit:** This technique is inspired by the Flutter [date_change_checker](https://github.com/error404sushant/date_change_checker) plugin.
138
130
 
139
131
  ### Web
140
132
 
@@ -15,28 +15,41 @@ public class DateTimeSettingPlugin: CAPPlugin {
15
15
  /**
16
16
  * Check if automatic time is enabled on the device.
17
17
  *
18
- * Note: iOS does not provide an API to check this setting.
19
- * This method returns false as iOS doesn't expose this information.
18
+ * iOS Implementation:
19
+ * Uses NSTimeZone.autoupdatingCurrent comparison with NSTimeZone.system
20
+ * to determine if automatic date/time is enabled.
21
+ *
22
+ * When auto date/time is ON: autoupdatingCurrent equals system timezone
23
+ * When auto date/time is OFF: they may differ
20
24
  */
21
25
  @objc func timeIsAuto(_ call: CAPPluginCall) {
22
- // iOS does not provide API to check auto time setting
23
- // We return false as we cannot determine the actual state
26
+ let autoUpdatingTimeZone = NSTimeZone.autoupdatingCurrent
27
+ let systemTimeZone = NSTimeZone.system
28
+
29
+ // If they are equal, auto date/time is likely enabled
30
+ let isAutoEnabled = autoUpdatingTimeZone.isEqual(to: systemTimeZone)
31
+
24
32
  call.resolve([
25
- "value": false
33
+ "value": isAutoEnabled
26
34
  ])
27
35
  }
28
36
 
29
37
  /**
30
38
  * Check if automatic timezone is enabled on the device.
31
39
  *
32
- * Note: iOS does not provide an API to check this setting.
33
- * This method returns false as iOS doesn't expose this information.
40
+ * iOS Implementation:
41
+ * Uses the same NSTimeZone comparison technique as timeIsAuto.
42
+ * This is because iOS doesn't separate auto time and auto timezone settings.
34
43
  */
35
44
  @objc func timeZoneIsAuto(_ call: CAPPluginCall) {
36
- // iOS does not provide API to check auto timezone setting
37
- // We return false as we cannot determine the actual state
45
+ let autoUpdatingTimeZone = NSTimeZone.autoupdatingCurrent
46
+ let systemTimeZone = NSTimeZone.system
47
+
48
+ // If they are equal, auto timezone is likely enabled
49
+ let isAutoEnabled = autoUpdatingTimeZone.isEqual(to: systemTimeZone)
50
+
38
51
  call.resolve([
39
- "value": false
52
+ "value": isAutoEnabled
40
53
  ])
41
54
  }
42
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatdayhr/capacitor-datetime-setting",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "Capacitor plugin to get information about auto time and auto timezone, open setting if not set to auto",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -11,7 +11,7 @@
11
11
  "android/src",
12
12
  "dist/",
13
13
  "ios/Plugin/",
14
- "CapacitorDatetimeSetting.podspec"
14
+ "GreatdayhrCapacitorDatetimeSetting.podspec"
15
15
  ],
16
16
  "author": "rakaraka029",
17
17
  "license": "MIT",