Refactored the raceClock
- created a class that hosts the raceClock - refactored the raceController to use a raceClock. #story[761]
This commit is contained in:
@@ -176,14 +176,8 @@ public class RaceController extends Controller {
|
||||
ongoingRacePane.setVisible(true);
|
||||
|
||||
//timezone
|
||||
TimeZoneLookup timeZoneLookup = new TimeZoneLookup();
|
||||
TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(raceXMLReader.getMark().getLatitude(), raceXMLReader.getMark().getLongitude());
|
||||
ZoneId zoneId = ZoneId.of(timeZoneResult.getResult());
|
||||
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
|
||||
ZonedDateTime zonedDateTime =localDateTime.atZone(zoneId);
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z");
|
||||
// System.out.println(dateTimeFormatter.format(zonedDateTime));
|
||||
timeZone.setText(dateTimeFormatter.format(zonedDateTime));
|
||||
RaceClock raceClock = new RaceClock(raceXMLReader.getMark());
|
||||
timeZone.textProperty().bind(raceClock.timeProperty());
|
||||
|
||||
initializeFPS();
|
||||
initializeAnnotations();
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package seng302.Model;
|
||||
|
||||
import com.github.bfsmith.geotimezone.TimeZoneLookup;
|
||||
import com.github.bfsmith.geotimezone.TimeZoneResult;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 19/04/2017.
|
||||
*/
|
||||
public class RaceClock {
|
||||
private StringProperty time;
|
||||
private DateTimeFormatter dateTimeFormatter;
|
||||
private ZoneId zoneId;
|
||||
|
||||
public RaceClock(GPSCoordinate gpsCoordinate){
|
||||
TimeZoneLookup timeZoneLookup = new TimeZoneLookup();
|
||||
TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(gpsCoordinate.getLatitude(), gpsCoordinate.getLongitude());
|
||||
ZoneId zoneId = ZoneId.of(timeZoneResult.getResult());
|
||||
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
|
||||
ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
|
||||
dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z");
|
||||
// System.out.println(dateTimeFormatter.format(zonedDateTime));
|
||||
time = new SimpleStringProperty(dateTimeFormatter.format(zonedDateTime));
|
||||
}
|
||||
|
||||
public void updateTime(){
|
||||
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
|
||||
ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
|
||||
time.setValue(dateTimeFormatter.format(zonedDateTime));
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time.get();
|
||||
}
|
||||
|
||||
public StringProperty timeProperty() {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user