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.time;
021
022import java.text.DateFormat;
023import java.util.Date;
024import java.util.Map;
025
026import com.google.common.collect.Maps;
027
028import org.apache.isis.applib.adapters.EncoderDecoder;
029import org.apache.isis.applib.adapters.Parser;
030import org.apache.isis.applib.value.Time;
031import org.apache.isis.core.commons.config.IsisConfiguration;
032import org.apache.isis.core.metamodel.facetapi.FacetHolder;
033import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
034
035public class TimeValueSemanticsProvider extends TimeValueSemanticsProviderAbstract<org.apache.isis.applib.value.Time> {
036
037    private static final Map<String, DateFormat> formats = Maps.newHashMap();
038
039    static {
040        initFormats(formats);
041    }
042
043    /**
044     * Required because implementation of {@link Parser} and
045     * {@link EncoderDecoder}.
046     */
047    public TimeValueSemanticsProvider() {
048        this(null, null, null);
049    }
050
051    public TimeValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
052        super(holder, org.apache.isis.applib.value.Time.class, configuration, context);
053    }
054
055    @Override
056    protected Map<String, DateFormat> formats() {
057        return formats;
058    }
059
060    @Override
061    protected boolean ignoreTimeZone() {
062        return true;
063    }
064
065    @Override
066    protected Time add(final Time original, final int years, final int months, final int days, final int hours, final int minutes) {
067        Time time = original;
068        time = time.add(hours, minutes);
069        return time;
070    }
071
072    @Override
073    protected Date dateValue(final Object object) {
074        final Time time = (Time) object;
075        return time == null ? null : time.asJavaDate();
076    }
077
078    @Override
079    protected Time now() {
080        return new Time();
081    }
082
083    @Override
084    protected Time setDate(final Date date) {
085        return new Time(date.getTime());
086    }
087
088}