Search in sources :

Example 96 with ZoneId

use of java.time.ZoneId in project teammates by TEAMMATES.

the class CoursesDb method makeAttributes.

@Override
protected CourseAttributes makeAttributes(Course entity) {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, entity);
    ZoneId courseTimeZone;
    try {
        courseTimeZone = ZoneId.of(entity.getTimeZone());
    } catch (DateTimeException e) {
        log.severe("Timezone '" + entity.getTimeZone() + "' of course '" + entity.getUniqueId() + "' is not supported. UTC will be used instead.");
        courseTimeZone = Const.DEFAULT_TIME_ZONE;
    }
    return CourseAttributes.builder(entity.getUniqueId(), entity.getName(), courseTimeZone).withCreatedAt(entity.getCreatedAt()).build();
}
Also used : DateTimeException(java.time.DateTimeException) ZoneId(java.time.ZoneId)

Example 97 with ZoneId

use of java.time.ZoneId in project tilesfx by HanSolo.

the class Tile method getTime.

/**
 * Returns the current time of the clock.
 * @return the current time of the clock
 */
public ZonedDateTime getTime() {
    if (null == time) {
        ZonedDateTime now = ZonedDateTime.now();
        time = new ObjectPropertyBase<ZonedDateTime>(now) {

            @Override
            protected void invalidated() {
                zoneId = get().getZone();
                fireTileEvent(RECALC_EVENT);
                if (!isRunning() && isAnimated()) {
                    long animationDuration = getAnimationDuration();
                    timeline.stop();
                    final KeyValue KEY_VALUE = new KeyValue(currentTime, now.toEpochSecond());
                    final KeyFrame KEY_FRAME = new KeyFrame(javafx.util.Duration.millis(animationDuration), KEY_VALUE);
                    timeline.getKeyFrames().setAll(KEY_FRAME);
                    timeline.setOnFinished(e -> fireTileEvent(FINISHED_EVENT));
                    timeline.play();
                } else {
                    currentTime.set(now.toEpochSecond());
                    fireTileEvent(FINISHED_EVENT);
                }
            }

            @Override
            public Object getBean() {
                return Tile.this;
            }

            @Override
            public String getName() {
                return "time";
            }
        };
    }
    return time.get();
}
Also used : EventHandler(javafx.event.EventHandler) Pos(javafx.geometry.Pos) Arrays(java.util.Arrays) Location(eu.hansolo.tilesfx.tools.Location) MovingAverage(eu.hansolo.tilesfx.tools.MovingAverage) BooleanBinding(javafx.beans.binding.BooleanBinding) ScheduledFuture(java.util.concurrent.ScheduledFuture) CountryGroup(eu.hansolo.tilesfx.tools.CountryGroup) RadarChart(eu.hansolo.tilesfx.chart.RadarChart) Control(javafx.scene.control.Control) ZonedDateTime(java.time.ZonedDateTime) Series(javafx.scene.chart.XYChart.Series) eu.hansolo.tilesfx.skins(eu.hansolo.tilesfx.skins) CountryPath(eu.hansolo.tilesfx.tools.CountryPath) ChartData(eu.hansolo.tilesfx.chart.ChartData) TimeData(eu.hansolo.tilesfx.tools.TimeData) Locale(java.util.Locale) TilesFXSeries(eu.hansolo.tilesfx.chart.TilesFXSeries) Country(eu.hansolo.tilesfx.tools.Country) Map(java.util.Map) LocalTime(java.time.LocalTime) SectionComparator(eu.hansolo.tilesfx.tools.SectionComparator) Helper.clamp(eu.hansolo.tilesfx.tools.Helper.clamp) ThreadFactory(java.util.concurrent.ThreadFactory) TimeEvent(eu.hansolo.tilesfx.events.TimeEvent) TimeEventType(eu.hansolo.tilesfx.events.TimeEvent.TimeEventType) Orientation(javafx.geometry.Orientation) Stop(javafx.scene.paint.Stop) TimeSectionComparator(eu.hansolo.tilesfx.tools.TimeSectionComparator) TimeEventListener(eu.hansolo.tilesfx.events.TimeEventListener) Font(javafx.scene.text.Font) Timeline(javafx.animation.Timeline) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Instant(java.time.Instant) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Platform(javafx.application.Platform) Objects(java.util.Objects) Duration(javafx.util.Duration) List(java.util.List) Interpolator(javafx.animation.Interpolator) TileEventListener(eu.hansolo.tilesfx.events.TileEventListener) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) Queue(java.util.Queue) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DarkSky(eu.hansolo.tilesfx.weather.DarkSky) Fonts(eu.hansolo.tilesfx.fonts.Fonts) AlarmEventListener(eu.hansolo.tilesfx.events.AlarmEventListener) EventType(eu.hansolo.tilesfx.events.TileEvent.EventType) FXCollections(javafx.collections.FXCollections) Mode(eu.hansolo.tilesfx.chart.RadarChart.Mode) SunburstChart(eu.hansolo.tilesfx.chart.SunburstChart) Skin(javafx.scene.control.Skin) Bindings(javafx.beans.binding.Bindings) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) Helper(eu.hansolo.tilesfx.tools.Helper) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TextAlignment(javafx.scene.text.TextAlignment) KeyValue(javafx.animation.KeyValue) Tooltip(javafx.scene.control.Tooltip) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) javafx.beans.property(javafx.beans.property) Properties(java.util.Properties) Status(javafx.animation.Animation.Status) NodeOrientation(javafx.geometry.NodeOrientation) SwitchEvent(eu.hansolo.tilesfx.events.SwitchEvent) Node(javafx.scene.Node) CategoryAxis(javafx.scene.chart.CategoryAxis) IOException(java.io.IOException) AlarmEvent(eu.hansolo.tilesfx.events.AlarmEvent) TimeUnit(java.util.concurrent.TimeUnit) MAX_PERIOD(eu.hansolo.tilesfx.tools.MovingAverage.MAX_PERIOD) TileEvent(eu.hansolo.tilesfx.events.TileEvent) Axis(javafx.scene.chart.Axis) InputStream(java.io.InputStream) KeyValue(javafx.animation.KeyValue) ZonedDateTime(java.time.ZonedDateTime) KeyFrame(javafx.animation.KeyFrame)

Example 98 with ZoneId

use of java.time.ZoneId in project muikku by otavanopisto.

the class PyramusGradingSchoolDataBridge method fromDateToOffsetDateTime.

private OffsetDateTime fromDateToOffsetDateTime(Date date) {
    Instant instant = date.toInstant();
    ZoneId systemId = ZoneId.systemDefault();
    ZoneOffset offset = systemId.getRules().getOffset(instant);
    return date.toInstant().atOffset(offset);
}
Also used : ZoneId(java.time.ZoneId) Instant(java.time.Instant) ZoneOffset(java.time.ZoneOffset)

Example 99 with ZoneId

use of java.time.ZoneId in project portfolio by buchen.

the class TimelineChart method paintTimeGrid.

private void paintTimeGrid(PaintEvent e) {
    IAxis xAxis = getAxisSet().getXAxis(0);
    Range range = xAxis.getRange();
    ZoneId zoneId = ZoneId.systemDefault();
    LocalDate start = Instant.ofEpochMilli((long) range.lower).atZone(zoneId).toLocalDate();
    LocalDate end = Instant.ofEpochMilli((long) range.upper).atZone(zoneId).toLocalDate();
    LocalDate cursor = start.getDayOfMonth() == 1 ? start : start.plusMonths(1).withDayOfMonth(1);
    Period period;
    DateTimeFormatter format;
    long days = ChronoUnit.DAYS.between(start, end);
    if (days < 250) {
        period = Period.ofMonths(1);
        // $NON-NLS-1$
        format = DateTimeFormatter.ofPattern("MMMM yyyy");
    } else if (days < 800) {
        period = Period.ofMonths(3);
        // $NON-NLS-1$
        format = DateTimeFormatter.ofPattern("QQQ yyyy");
        cursor = cursor.plusMonths((12 - cursor.getMonthValue() + 1) % 3);
    } else if (days < 1200) {
        period = Period.ofMonths(6);
        // $NON-NLS-1$
        format = DateTimeFormatter.ofPattern("QQQ yyyy");
        cursor = cursor.plusMonths((12 - cursor.getMonthValue() + 1) % 6);
    } else {
        period = Period.ofYears(days > 5000 ? 2 : 1);
        // $NON-NLS-1$
        format = DateTimeFormatter.ofPattern("yyyy");
        if (cursor.getMonthValue() > 1)
            cursor = cursor.plusYears(1).withDayOfYear(1);
    }
    while (cursor.isBefore(end)) {
        int y = xAxis.getPixelCoordinate((double) cursor.atStartOfDay(zoneId).toInstant().toEpochMilli());
        e.gc.drawLine(y, 0, y, e.height);
        e.gc.drawText(format.format(cursor), y + 5, 5);
        cursor = cursor.plus(period);
    }
}
Also used : ZoneId(java.time.ZoneId) Period(java.time.Period) Range(org.swtchart.Range) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) IAxis(org.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Example 100 with ZoneId

use of java.time.ZoneId in project portfolio by buchen.

the class TimelineChart method toJavaUtilDate.

public static Date[] toJavaUtilDate(LocalDate[] dates) {
    ZoneId zoneId = ZoneId.systemDefault();
    Date[] answer = new Date[dates.length];
    for (int ii = 0; ii < answer.length; ii++) answer[ii] = Date.from(dates[ii].atStartOfDay().atZone(zoneId).toInstant());
    return answer;
}
Also used : ZoneId(java.time.ZoneId) Date(java.util.Date) LocalDate(java.time.LocalDate) Point(org.eclipse.swt.graphics.Point)

Aggregations

ZoneId (java.time.ZoneId)420 Test (org.junit.Test)137 ZonedDateTime (java.time.ZonedDateTime)108 LocalDateTime (java.time.LocalDateTime)69 LocalDate (java.time.LocalDate)55 Instant (java.time.Instant)49 Test (org.testng.annotations.Test)41 ZoneOffset (java.time.ZoneOffset)37 DateTimeFormatter (java.time.format.DateTimeFormatter)32 Date (java.util.Date)29 ArrayList (java.util.ArrayList)23 LocalTime (java.time.LocalTime)21 TemporalAccessor (java.time.temporal.TemporalAccessor)15 List (java.util.List)15 HashMap (java.util.HashMap)14 Clock (java.time.Clock)13 Collectors (java.util.stream.Collectors)13 DateTimeException (java.time.DateTimeException)12 Duration (java.time.Duration)12 OffsetDateTime (java.time.OffsetDateTime)11