- created a class that hosts the raceClock - refactored the raceController to use a raceClock. #story[761]main
parent
7790322e04
commit
e501102bc5
@ -0,0 +1,3 @@
|
|||||||
|
<component name="CopyrightManager">
|
||||||
|
<settings default="" />
|
||||||
|
</component>
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue