cherry.goods.util.LocalDateUtil.java Source code

Java tutorial

Introduction

Here is the source code for cherry.goods.util.LocalDateUtil.java

Source

/*
 * Copyright 2014,2015 agwlvssainokuni
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cherry.goods.util;

import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;

/**
 * ?<br />
 * ????
 * <ul>
 * <li>(FROM)?? ({@link #rangeFrom(LocalDate)}, {@link #rangeFrom(LocalDateTime)},
 * {@link #ymRangeFrom(LocalDate)}</li>
 * <li>(TO)?? ({@link #rangeTo(LocalDate)}, {@link #rangeTo(LocalDateTime)}, {@link #ymRangeTo(LocalDate)}</li>
 * </ul>
 */
public class LocalDateUtil {

    /**
     * (FROM)???
     * 
     * @param from ??
     * @return ????(FROM)??
     */
    public static LocalDate rangeFrom(LocalDate from) {
        return from;
    }

    /**
     * (FROM)???
     * 
     * @param from ??
     * @return ????(FROM)??
     */
    public static LocalDate rangeFrom(LocalDateTime from) {
        if (from == null) {
            return null;
        }
        return from.toLocalDate();
    }

    /**
     * (TO)???
     * 
     * @param to ??
     * @return ????(TO)??
     */
    public static LocalDate rangeTo(LocalDate to) {
        if (to == null) {
            return null;
        }
        return to.plusDays(1);
    }

    /**
     * (TO)???
     * 
     * @param to ??
     * @return ????(TO)??
     */
    public static LocalDate rangeTo(LocalDateTime to) {
        if (to == null) {
            return null;
        }
        return to.toLocalDate().plusDays(1);
    }

    /**
     * (??)?????(Y/M/1?)???
     * 
     * @param dt ??
     * @return (??)???
     */
    public static LocalDate normalizeYm(LocalDate dt) {
        if (dt == null) {
            return null;
        }
        return new LocalDate(dt.getYear(), dt.getMonthOfYear(), 1);
    }

    /**
     * (??)??(FROM)???
     * 
     * @param from ??(??)
     * @return ??(??)??(FROM)??
     */
    public static LocalDate ymRangeFrom(LocalDate from) {
        return normalizeYm(from);
    }

    /**
     * (??)??(TO)???
     * 
     * @param to ??(??)
     * @return ??(??)??(TO)??
     */
    public static LocalDate ymRangeTo(LocalDate to) {
        if (to == null) {
            return null;
        }
        return normalizeYm(to).plusMonths(1);
    }

}