Skip to content

Commit

Permalink
fix: timezone error handling (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
henninghall committed Dec 3, 2023
1 parent caf03e6 commit 471120c
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions android/src/main/java/com/henninghall/date_picker/State.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.henninghall.date_picker;

import android.util.Log;

import com.facebook.react.bridge.Dynamic;
import com.henninghall.date_picker.models.Is24HourSource;
import com.henninghall.date_picker.models.Mode;
Expand Down Expand Up @@ -103,16 +105,21 @@ public Calendar getMaximumDate() {
}

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() {
Expand Down

0 comments on commit 471120c

Please sign in to comment.