Skip to content

Commit

Permalink
Seems to deal with DST properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryan-lunt committed Sep 8, 2015
1 parent b4aad7b commit 6edc510
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ public int getDurationDays(){
//Should return end_date - start_date, but that would be too easy, wouldn't it.
//Java has no timedelta or datedelta, so everyone implements their own. :'(

long delta = end_date.getTimeInMillis() - start_date.getTimeInMillis();
//Deals with the fact that we really want to count the days, but we're unfortunately doing that by dividing by hours.
//Calendar.get(Calendar.DST_OFFSET) will get the number of milliseconds that the timezone was offset from its normal time as a result of DST in that location.
//TODO: Consider making the whole program timezone-agnostic. (Pretend everything happens in Greenwich, England?)

long offset_delta_dst = end_date.get(end_date.DST_OFFSET) - start_date.get(start_date.DST_OFFSET);

long delta = end_date.getTimeInMillis() - start_date.getTimeInMillis() + offset_delta_dst;
return (int)java.lang.Math.ceil(delta / (1000.0*60*60*24));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.sandiegozoo.pathology.contact_tracer;

import java.io.*;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.sandiegozoo.pathology.contact_tracer.dataimport.*;
import org.sandiegozoo.pathology.database.domain.*;

import junit.framework.TestCase;

public class DaylightSavingsTimeTest extends MyBase {


CTIOHandler timeline_reader;
CTIOHandler infection_reader;

public void setUp(){

// A SessionFactory is set up once for an application
this.setupFactory();

timeline_reader = new TimelineHandler(new File(getClass().getClassLoader().getResource("DSTTestFiles/dst_timeline.txt").getFile()));
timeline_reader.setSessionFactory(sessionFactory);
infection_reader = new InfectionHandler(new File(getClass().getClassLoader().getResource("DSTTestFiles/dst_infections.txt").getFile()));
infection_reader.setSessionFactory(sessionFactory);


}

public void testTracer(){

System.out.println("LOADING TIMELINE");

//Attempt loading the timeline file
try {
timeline_reader.call();
} catch (Exception e) {
this.fail(e.getMessage());
}

System.out.println("LOADING INFECTIONS");

//Attempt loading the infection file
try {
infection_reader.call();
} catch (Exception e) {
this.fail(e.getMessage());
}


ContactTracer myTracer = new ContactTracer(sessionFactory);

myTracer.process_contaminations();
myTracer.process_exposures();

System.out.println("FINISHED CONTACT TRACER");

Session session = sessionFactory.openSession();
Query find_contaminations = session.createQuery("from Contamination");
List<Contamination> my_contaminations = (List<Contamination>)find_contaminations.list();
for(Contamination one_contam : my_contaminations){
System.out.println("FOUND A CONTAMINATION: " + one_contam);
}

Query find_exposures = session.createQuery("from Exposure");
List<Exposure> my_exposures = (List<Exposure>)find_exposures.list();
for(Exposure one_exp : my_exposures){
System.out.println("FOUND AN EXPOSURE: " + one_exp);
}

session.close();
}

}
1 change: 1 addition & 0 deletions src/test/resources/DSTTestFiles/dst_infections.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Infected, 0, 1984-02-02, 2010-01-01
2 changes: 2 additions & 0 deletions src/test/resources/DSTTestFiles/dst_timeline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Infected, HotelCalifornia, 1998-10-18, 1998-11-10
Target, HotelCalifornia, 1990-01-01, 2000-01-01

0 comments on commit 6edc510

Please sign in to comment.