Browse Source

fix: timezone error handling (#719)

master
Henning Hall 1 year ago
committed by GitHub
parent
commit
471120c7b1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 10 deletions
  1. +17
    -10
      android/src/main/java/com/henninghall/date_picker/State.java

+ 17
- 10
android/src/main/java/com/henninghall/date_picker/State.java View File

@ -1,5 +1,7 @@
package com.henninghall.date_picker; package com.henninghall.date_picker;
import android.util.Log;
import com.facebook.react.bridge.Dynamic; import com.facebook.react.bridge.Dynamic;
import com.henninghall.date_picker.models.Is24HourSource; import com.henninghall.date_picker.models.Is24HourSource;
import com.henninghall.date_picker.models.Mode; import com.henninghall.date_picker.models.Mode;
@ -103,16 +105,21 @@ public class State {
} }
public TimeZone getTimeZone() { public TimeZone getTimeZone() {
String offsetString = timezoneOffsetInMinutesProp.getValue();
if(offsetString == null || offsetString.equals("")) return TimeZone.getDefault();
int offset = Integer.parseInt(offsetString);
int totalOffsetMinutes = Math.abs(offset);
char offsetDirection = offset < 0 ? '-' : '+';
int offsetHours = (int) Math.floor(totalOffsetMinutes / 60f);
int offsetMinutes = totalOffsetMinutes - offsetHours * 60;
String timeZoneId = "GMT" + offsetDirection + offsetHours + ":" + Utils.toPaddedMinutes(offsetMinutes);
TimeZone zone = TimeZone.getTimeZone(timeZoneId);
return zone;
try{
String offsetString = timezoneOffsetInMinutesProp.getValue();
if(offsetString == null || offsetString.equals("")) return TimeZone.getDefault();
int offset = Integer.parseInt(offsetString);
int totalOffsetMinutes = Math.abs(offset);
char offsetDirection = offset < 0 ? '-' : '+';
int offsetHours = (int) Math.floor(totalOffsetMinutes / 60f);
int offsetMinutes = totalOffsetMinutes - offsetHours * 60;
String timeZoneId = "GMT" + offsetDirection + offsetHours + ":" + Utils.toPaddedMinutes(offsetMinutes);
TimeZone zone = TimeZone.getTimeZone(timeZoneId);
return zone;
} catch (Exception e){
e.printStackTrace();
return TimeZone.getDefault();
}
} }
public String getIsoDate() { public String getIsoDate() {

Loading…
Cancel
Save