Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions src/main/java/org/mtransit/android/commons/TimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,6 @@ public static String formatTime(@NonNull Context context, @NonNull Date date) {
return getFormatTime(context, date.getTime()).formatThreadSafe(date);
}

@SuppressWarnings("unused")
@NonNull
public static String formatTime(boolean realTime, @NonNull Context context, long timeInMs) {
return cleanNoRealTime(realTime,
formatTime(context, timeInMs)
);
}

@NonNull
public static String formatTime(@NonNull Context context, long timeInMs) {
return getFormatTime(context, timeInMs).formatThreadSafe(timeInMs);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/mtransit/android/commons/data/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public int getTimestampsCount() {
@Nullable
public TimeZone getTimeZone() {
for (Timestamp timestamp : this.timestamps) {
final String localTimeZoneId = timestamp.getLocalTimeZone();
final String localTimeZoneId = timestamp.getLocalTimeZoneId();
if (localTimeZoneId != null) {
return TimeZone.getTimeZone(localTimeZoneId);
}
Expand Down Expand Up @@ -602,17 +602,17 @@ private String getNewHeading() {
return Direction.getNewHeading(this.headsignType, this.headsignValue);
}

private void setLocalTimeZone(@Nullable String localTimeZone) {
private void setLocalTimeZoneId(@Nullable String localTimeZone) {
this.localTimeZoneId = localTimeZone;
}

@Nullable
public String getLocalTimeZone() {
public String getLocalTimeZoneId() {
return localTimeZoneId;
}

@Deprecated
public boolean hasLocalTimeZone() {
public boolean hasLocalTimeZoneId() {
return !TextUtils.isEmpty(this.localTimeZoneId);
}
Comment thread
mmathieum marked this conversation as resolved.

Expand Down Expand Up @@ -826,7 +826,7 @@ static Timestamp parseJSON(@NonNull JSONObject jTimestamp) {
}
String localTimeZone = jTimestamp.optString(JSON_LOCAL_TIME_ZONE);
if (!TextUtils.isEmpty(localTimeZone)) {
timestamp.setLocalTimeZone(localTimeZone);
timestamp.setLocalTimeZoneId(localTimeZone);
}
if (jTimestamp.has(JSON_REAL_TIME)) {
timestamp.setRealTime(jTimestamp.optBoolean(JSON_REAL_TIME, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private void processNouvelle() throws ParseException {

private static final String DATE_HEURE_FORMAT_FR_PATTERN = "yyyy-MM-dd HH:mm";
private static final String DATE_HEURE_FORMAT_EN_PATTERN = "MM-dd-yyyy HH:mm";
private static final String TIME_ZONE = "America/Montreal";
private static final String TIME_ZONE_ID = "America/Montreal";
@Nullable
private static ThreadSafeDateFormatter dateHeureFormat;

Expand All @@ -773,7 +773,7 @@ static ThreadSafeDateFormatter getDateHeureFormat() {
dateHeureFormat = new ThreadSafeDateFormatter(
isLanguageFrench() ? DATE_HEURE_FORMAT_FR_PATTERN : DATE_HEURE_FORMAT_EN_PATTERN,
isLanguageFrench() ? Locale.CANADA_FRENCH : Locale.CANADA);
dateHeureFormat.setTimeZone(TimeZone.getTimeZone(TIME_ZONE));
dateHeureFormat.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_ID));
}
return dateHeureFormat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private void loadRealTimeStatusFromWWW(@NonNull RouteDirectionStop rds) {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
CleverDevicesPredictionsDataHandler handler = new CleverDevicesPredictionsDataHandler(this, newLastUpdateInMs, AgencyUtils.getRDSAgencyTimeZone(context), sourceLabel, rds);
CleverDevicesPredictionsDataHandler handler = new CleverDevicesPredictionsDataHandler(this, newLastUpdateInMs, AgencyUtils.getRDSAgencyTimeZoneId(context), sourceLabel, rds);
xr.setContentHandler(handler);
xr.parse(new InputSource(httpUrlConnection.getInputStream()));
Collection<POIStatus> statuses = handler.getStatuses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1209,12 +1209,12 @@ private ThreadSafeDateFormatter getTimeParser(@NonNull Context context) {
formatter += StringUtils.SPACE_STRING + getAGENCY_TIME_AM_PM_FORMAT(context);
}
timeParser = new ThreadSafeDateFormatter(formatter, Locale.ENGLISH);
String agencyTimeZone = getAGENCY_TIME_ZONE(context);
if (TextUtils.isEmpty(agencyTimeZone)) {
agencyTimeZone = AgencyUtils.getRDSAgencyTimeZone(context);
String agencyTimeZoneId = getAGENCY_TIME_ZONE(context);
if (TextUtils.isEmpty(agencyTimeZoneId)) {
agencyTimeZoneId = AgencyUtils.getRDSAgencyTimeZoneId(context);
}
if (!TextUtils.isEmpty(agencyTimeZone)) {
timeParser.setTimeZone(TimeZone.getTimeZone(agencyTimeZone));
if (!TextUtils.isEmpty(agencyTimeZoneId)) {
timeParser.setTimeZone(TimeZone.getTimeZone(agencyTimeZoneId));
}
} catch (Exception e) {
MTLog.w(LOG_TAG, e, "Error while initializing time formatter!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void loadRealTimeStatusFromWWW(@NonNull RouteDirectionStop rds) {
switch (httpUrlConnection.getResponseCode()) {
case HttpURLConnection.HTTP_OK:
long newLastUpdateInMs = TimeUtils.currentTimeMillis();
String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZone(context);
String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZoneId(context);
String jsonString = FileUtils.getString(urlc.getInputStream());
MTLog.d(this, "loadRealTimeStatusFromWWW() > jsonString: %s.", jsonString);
Collection<POIStatus> statuses = parseAgencyJSON(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private Collection<? extends POIStatus> parseAgencyJSON(@NonNull Context context
@NonNull RouteDirectionStop rds,
@Nullable String sourceLabel,
long newLastUpdateInMs) {
final String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZone(context);
final String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZoneId(context);
try {
ArrayMap<String, Schedule> result = new ArrayMap<>();
final int destinationNumber = pickRDSDestination(context, jStopResponse, rds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ private void loadPredictionsFromWWW(@NonNull Context context, @NonNull RouteDire
final SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser sp = spf.newSAXParser();
final XMLReader xr = sp.getXMLReader();
final NextBusPredictionsDataHandler handler = new NextBusPredictionsDataHandler(this, sourceLabel, newLastUpdateInMs, AgencyUtils.getRDSAgencyTimeZone(context));
final NextBusPredictionsDataHandler handler = new NextBusPredictionsDataHandler(this, sourceLabel, newLastUpdateInMs, AgencyUtils.getRDSAgencyTimeZoneId(context));
xr.setContentHandler(handler);
xr.parse(new InputSource(response.body().byteStream()));
final Collection<? extends POIStatus> statuses = handler.getStatuses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private void loadPredictionsFromWWW(@NonNull Context context, @NonNull RouteDire
switch (response.code()) {
case HttpURLConnection.HTTP_OK:
final long newLastUpdateInMs = TimeUtils.currentTimeMillis();
final String localeTimeZoneId = AgencyUtils.getRDSAgencyTimeZone(context);
final String localeTimeZoneId = AgencyUtils.getRDSAgencyTimeZoneId(context);
final String jsonString = FileUtils.getString(response.body().byteStream());
MTLog.d(this, "loadPredictionsFromWWW() > jsonString: %s.", jsonString);
JGetNextTripsForStop jGetNextTripsForStop = parseAgencyJSONArrivals(jsonString);
Expand Down Expand Up @@ -386,7 +386,7 @@ private void loadPredictionsFromWWW(@NonNull Context context, @NonNull RouteDire
static ThreadSafeDateFormatter getDateFormat(@NonNull Context context) {
if (dateFormat == null) {
dateFormat = new ThreadSafeDateFormatter(DATE_FORMAT_PATTERN, Locale.ENGLISH);
dateFormat.setTimeZone(TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZone(context)));
dateFormat.setTimeZone(TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZoneId(context)));
}
return dateFormat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private void loadPredictionsFromWWW(@NonNull Context context, @NonNull RouteDire

private Collection<POIStatus> parseAgencyJSON(@NonNull Context context, @Nullable String jsonString, @NonNull RouteDirectionStop rds, @Nullable String sourceLabel, long newLastUpdateInMs) {
try {
final String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZone(context);
final String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZoneId(context);
ArrayList<POIStatus> result = new ArrayList<>();
JSONObject json = jsonString == null ? null : new JSONObject(jsonString);
if (json != null && json.has(JSON_DATA)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ private ArrayList<News> loadAgencyNewsDataFromWWW(@NonNull Context context, Stri
final boolean ignoreGUID = RssNewProviderUtils.pickIgnoreGUID(context, i);
final boolean ignoreLink = RssNewProviderUtils.pickIgnoreLink(context, i);
final Pair<String, String> dateLinkFallback = RssNewProviderUtils.pickDateLinkFallback(context, i);
final String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZone(context);
final String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZoneId(context);
final RSSDataHandler handler = new RSSDataHandler(
url,
authority,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object AgencyUtils {
private var _timeZone: String? = null

@JvmStatic
fun getRDSAgencyTimeZone(context: Context): String =
fun getRDSAgencyTimeZoneId(context: Context): String =
Comment thread
mmathieum marked this conversation as resolved.
_timeZone ?: context.getString(R.string.gtfs_rts_timezone) // do not change to avoid breaking compat w/ old modules
.takeIf { it.isNotBlank() }
?: TimeZone.getDefault().id // TODO support for bike_station
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static ScheduleTimestamps getScheduleTimestamps(@NonNull GTFSProvider pro
final Context context = provider.requireContextCompat();
final ThreadSafeDateFormatter dateFormat = GTFSStatusProvider.getDateFormat(context);
final ThreadSafeDateFormatter timeFormat = GTFSStatusProvider.getTimeFormat(context);
final TimeZone timeZone = TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZone(context));
final TimeZone timeZone = TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZoneId(context));
final Calendar startsAt = TimeUtils.getNewCalendar(timeZone, startsAtInMs);
startsAt.add(Calendar.DATE, -1); // starting yesterday
Set<Schedule.Timestamp> dayTimestamps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static POIStatus getNewStatus(@NonNull GTFSProvider provider, @NonNull St
static ThreadSafeDateFormatter getDateFormat(@NonNull Context context) {
if (dateFormat == null) {
dateFormat = new ThreadSafeDateFormatter(DATE_FORMAT_PATTERN, Locale.ENGLISH);
dateFormat.setTimeZone(TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZone(context)));
dateFormat.setTimeZone(TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZoneId(context)));
}
return dateFormat;
}
Expand All @@ -190,7 +190,7 @@ static ThreadSafeDateFormatter getDateFormat(@NonNull Context context) {
static ThreadSafeDateFormatter getTimeFormat(@NonNull Context context) {
if (timeFormat == null) {
timeFormat = new ThreadSafeDateFormatter(TIME_FORMAT_PATTERN, Locale.ENGLISH);
timeFormat.setTimeZone(TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZone(context)));
timeFormat.setTimeZone(TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZoneId(context)));
}
return timeFormat;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ private static ArrayList<Schedule.Timestamp> findTimestamps(@NonNull GTFSProvide
final Context context = provider.requireContextCompat();
final ThreadSafeDateFormatter dateFormat = getDateFormat(context);
final ThreadSafeDateFormatter timeFormat = getTimeFormat(context);
final TimeZone timeZone = TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZone(context));
final TimeZone timeZone = TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZoneId(context));
final Calendar startsAt = TimeUtils.getNewCalendar(timeZone, timestamp);
if (lookBehindInMs > PROVIDER_PRECISION_IN_MS) {
if (lookBehindInMs > 0L) {
Expand Down Expand Up @@ -435,7 +435,7 @@ static Set<Schedule.Timestamp> findScheduleList(
BufferedReader br = null;
String line = null;
final Context context = provider.requireContextCompat();
final String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZone(context);
final String localTimeZoneId = AgencyUtils.getRDSAgencyTimeZoneId(context);
String fileName = String.format(getSTOP_SCHEDULE_RAW_FILE_FORMAT(context), stopId);
try {
@SuppressLint("DiscouragedApi")
Expand Down Expand Up @@ -603,7 +603,7 @@ private static ArrayList<Schedule.Frequency> findFrequencies(@NonNull GTFSProvid
final Context context = provider.requireContextCompat();
final ThreadSafeDateFormatter dateFormat = getDateFormat(context);
final ThreadSafeDateFormatter timeFormat = getTimeFormat(context);
final TimeZone timeZone = TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZone(context));
final TimeZone timeZone = TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZoneId(context));
final Calendar startsAt = TimeUtils.getNewCalendar(timeZone, timestamp);
startsAt.add(Calendar.DATE, -1); // starting yesterday
HashSet<Schedule.Frequency> dayFrequencies;
Expand Down Expand Up @@ -765,7 +765,7 @@ private static Long convertToTimestamp(Context context, int timeInt, String date
private static ThreadSafeDateFormatter getToTimestampFormat(Context context) {
if (toTimestampFormat == null) {
toTimestampFormat = new ThreadSafeDateFormatter(TO_TIMESTAMP_FORMAT_PATTERN, Locale.ENGLISH);
toTimestampFormat.setTimeZone(TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZone(context)));
toTimestampFormat.setTimeZone(TimeZone.getTimeZone(AgencyUtils.getRDSAgencyTimeZoneId(context)));
}
return toTimestampFormat;
}
Expand Down