Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timezone error handling #719

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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