All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hprose.io.convert.java8.PeriodConverter Maven / Gradle / Ivy

/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * PeriodConverter.java                                   *
 *                                                        *
 * PeriodConverter class for Java.                        *
 *                                                        *
 * LastModified: Aug 6, 2016                              *
 * Author: Ma Bingyao                   *
 *                                                        *
\**********************************************************/
package hprose.io.convert.java8;

import hprose.io.convert.Converter;
import hprose.util.DateTime;
import java.lang.reflect.Type;
import java.time.Period;

public class PeriodConverter implements Converter {

    public final static PeriodConverter instance = new PeriodConverter();

    public Period convertTo(DateTime dt) {
        return Period.of(dt.year, dt.month, dt.day);
    }

    public Period convertTo(Object obj, Type type) {
        if (obj instanceof DateTime) {
            return convertTo((DateTime) obj);
        }
        else if (obj instanceof String) {
            return Period.parse((String) obj);
        }
        else if (obj instanceof char[]) {
            return Period.parse(new String((char[]) obj));
        }
        return (Period) obj;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy