You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.8 KiB
54 lines
1.8 KiB
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 String timeZone;
|
|
private ZoneId zoneId;
|
|
|
|
public RaceClock(GPSCoordinate gpsCoordinate){
|
|
TimeZoneLookup timeZoneLookup = new TimeZoneLookup();
|
|
TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(gpsCoordinate.getLatitude(), gpsCoordinate.getLongitude());
|
|
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));
|
|
DateTimeFormatter timeZoneFormatter = DateTimeFormatter.ofPattern("z");
|
|
timeZone = timeZoneFormatter.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;
|
|
}
|
|
|
|
public String getTimeZone() {
|
|
return timeZone;
|
|
}
|
|
}
|