001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.extensions.markup.html.form.datetime;
018
019import java.time.LocalDate;
020import java.time.LocalTime;
021import java.time.ZoneId;
022import java.time.ZonedDateTime;
023
024import org.apache.wicket.model.IModel;
025
026/**
027 * Works on a {@link java.time.ZonedDateTime} object. See {@link AbstractDateTimeField} for
028 * further details.
029 * 
030 * @author eelcohillenius
031 */
032public class ZonedDateTimeField extends AbstractDateTimeField<ZonedDateTime>
033{
034        private static final long serialVersionUID = 1L;
035
036        /**
037         * Construct.
038         * 
039         * @param id
040         */
041        public ZonedDateTimeField(final String id)
042        {
043                this(id, null);
044        }
045
046        /**
047         * Construct.
048         * 
049         * @param id
050         * @param model
051         */
052        public ZonedDateTimeField(final String id, final IModel<ZonedDateTime> model)
053        {
054                super(id, model);
055
056                // Sets the type that will be used when updating the model for this component.
057                setType(ZonedDateTime.class);
058        }
059
060        /**
061         * Creates a zoned date time in the systems default zone.
062         * 
063         * @see ZoneId#systemDefault()
064         */
065        @Override
066        protected ZonedDateTime createTemporal(LocalDate date, LocalTime time) {
067                return ZonedDateTime.of(date, time, ZoneId.systemDefault());
068        }
069
070        @Override
071        protected LocalDate getLocalDate(ZonedDateTime temporal)
072        {
073                return temporal.toLocalDate();
074        }
075
076        @Override
077        protected LocalTime getLocalTime(ZonedDateTime temporal)
078        {
079                return temporal.toLocalTime();
080        }
081}