001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019
020package org.apache.isis.core.progmodel.facets.value.datetime;
021
022import java.util.Date;
023
024import org.apache.isis.applib.adapters.EncoderDecoder;
025import org.apache.isis.applib.adapters.Parser;
026import org.apache.isis.applib.value.DateTime;
027import org.apache.isis.core.commons.config.IsisConfiguration;
028import org.apache.isis.core.metamodel.facetapi.FacetHolder;
029import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
030import org.apache.isis.core.progmodel.facets.value.DateAndTimeValueSemanticsProviderAbstract;
031
032public class DateTimeValueSemanticsProvider extends DateAndTimeValueSemanticsProviderAbstract<DateTime> {
033
034    /**
035     * Required because implementation of {@link Parser} and
036     * {@link EncoderDecoder}.
037     */
038    public DateTimeValueSemanticsProvider() {
039        this(null, null, null);
040    }
041
042    public DateTimeValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
043        super(holder, DateTime.class, Immutability.NOT_IMMUTABLE, EqualByContent.NOT_HONOURED, configuration, context);
044    }
045
046    @Override
047    protected Date dateValue(final Object value) {
048        final DateTime date = (DateTime) value;
049        return date == null ? null : date.dateValue();
050    }
051
052    @Override
053    protected DateTime add(final DateTime original, final int years, final int months, final int days, final int hours, final int minutes) {
054        DateTime date = original;
055        date = date.add(years, months, days, hours, minutes);
056        return date;
057    }
058
059    @Override
060    protected DateTime now() {
061        return new DateTime();
062    }
063
064    @Override
065    protected DateTime setDate(final Date date) {
066        return new DateTime(date);
067    }
068
069}