Skip to content

Commit

Permalink
Fix for issue #26. UpdateTravelTimes now working. Date formats also r…
Browse files Browse the repository at this point in the history
…eset.
  • Loading branch information
scrudden committed Jan 20, 2018
1 parent 1f47bec commit 4cf31db
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ public static List<ArrivalDeparture> getArrivalsDeparturesFromDb(
IntervalTimer timer = new IntervalTimer();

// Get the database session. This is supposed to be pretty light weight
Session session = dbName != null ? HibernateUtils.getSession(dbName, true) : HibernateUtils.getSession(true);
Session session = dbName != null ? HibernateUtils.getSession(dbName, false) : HibernateUtils.getSession(true);

// Create the query. Table name is case sensitive and needs to be the
// class name instead of the name of the db table.
Expand Down Expand Up @@ -827,7 +827,7 @@ public static Long getArrivalsDeparturesCountFromDb(
IntervalTimer timer = new IntervalTimer();
Long count = null;
// Get the database session. This is supposed to be pretty light weight
Session session = dbName != null ? HibernateUtils.getSession(dbName, true) : HibernateUtils.getSession(true);
Session session = dbName != null ? HibernateUtils.getSession(dbName, false) : HibernateUtils.getSession(true);

// Create the query. Table name is case sensitive and needs to be the
// class name instead of the name of the db table.
Expand Down
4 changes: 2 additions & 2 deletions transitime/src/main/java/org/transitime/db/structs/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static List<Match> getMatchesFromDb(
IntervalTimer timer = new IntervalTimer();

// Get the database session. This is supposed to be pretty light weight
Session session = HibernateUtils.getSession(projectId, true);
Session session = HibernateUtils.getSession(projectId, false);

// Create the query. Table name is case sensitive and needs to be the
// class name instead of the name of the db table.
Expand Down Expand Up @@ -352,7 +352,7 @@ public static Long getMatchesCountFromDb(
IntervalTimer timer = new IntervalTimer();

// Get the database session. This is supposed to be pretty light weight
Session session = HibernateUtils.getSession(projectId, true);
Session session = HibernateUtils.getSession(projectId, false);

// Create the query. Table name is case sensitive and needs to be the
// class name instead of the name of the db table.
Expand Down
11 changes: 10 additions & 1 deletion transitime/src/main/java/org/transitime/db/structs/Trip.java
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,16 @@ public static Long countTravelTimesForTrips(Session session,
query.setInteger("rev", travelTimesRev);
Long count = null;
try {
Integer bcount = (Integer) query.uniqueResult();

Integer bcount;
if(query.uniqueResult() instanceof BigInteger)
{
bcount = ((BigInteger)query.uniqueResult()).intValue();
}else
{
bcount = (Integer) query.uniqueResult();
}

if (bcount != null)
count = bcount.longValue();
} catch (HibernateException e) {
Expand Down
22 changes: 10 additions & 12 deletions transitime/src/main/java/org/transitime/utils/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,27 @@ public class Time {

// These two are for reading in dates in various formats
private static final DateFormat defaultDateFormat =
new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat.getDateInstance(DateFormat.SHORT);
private static final DateFormat dateFormatDashesShortYear =

new SimpleDateFormat("MM-dd-yy");


private static final DateFormat readableDateFormat =
new SimpleDateFormat("yyyy-MM-dd");
new SimpleDateFormat("MM-dd-yyyy");

private static final DateFormat readableDateFormat24 =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
new SimpleDateFormat("MM-dd-yyyy HH:mm:ss z");

private static final DateFormat readableDateFormat24NoSecs =
new SimpleDateFormat("yyyy-MM-dd HH:mm");
new SimpleDateFormat("MM-dd-yyyy HH:mm");

private static final DateFormat readableDateFormat24Msec =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
new SimpleDateFormat("MM-dd-yyyy HH:mm:ss.SSS z");

private static final DateFormat readableDateFormat24NoTimeZoneMsec =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
new SimpleDateFormat("MM-dd-yyyy HH:mm:ss.SSS");

private static final DateFormat readableDateFormat24NoTimeZoneNoMsec =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");

private static final DateFormat timeFormat24 =
new SimpleDateFormat("HH:mm:ss z");
Expand All @@ -120,11 +118,11 @@ public class Time {
// Note that this one is not static. It is for when need to include
// timezone via a Time object.
private final DateFormat readableDateFormat24MsecForTimeZone =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
new SimpleDateFormat("MM-dd-yyyy HH:mm:ss.SSS z");
private final DateFormat readableTimeFormatForTimeZone =
new SimpleDateFormat("HH:mm:ss");
private final DateFormat readableDateFormatForTimeZone =
new SimpleDateFormat("yyyy-MM-dd");
new SimpleDateFormat("MM-dd-yyyy");

// So can output headings and such with a consistent number of decimal places
private static final DecimalFormat oneDigitFormat = new DecimalFormat("0.0");
Expand Down Expand Up @@ -444,7 +442,7 @@ public static Date parse(String datetimeStr) throws ParseException {

/**
* Parses the dateStr and returns a Date object. Format of
* date is "yyyy-MM-dd".
* date is "MM-dd-yyyy".
*
* @param dateStr
* @return
Expand Down

0 comments on commit 4cf31db

Please sign in to comment.