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

com.yuehuanghun.mybatis.milu.tool.converter.impl.LocalTimeConverter Maven / Gradle / Ivy

There is a newer version: 1.18.0
Show newest version
package com.yuehuanghun.mybatis.milu.tool.converter.impl;

import java.time.LocalTime;
import java.time.ZoneId;

import com.yuehuanghun.mybatis.milu.exception.OrmRuntimeException;
import com.yuehuanghun.mybatis.milu.tool.StringUtils;
import com.yuehuanghun.mybatis.milu.tool.converter.Converter;

public class LocalTimeConverter implements Converter {
	@Override
	public LocalTime convert(Object target) {
		if(target == null) {
			return null;
		}
		if(LocalTime.class.isInstance(target)) {
			return (LocalTime) target;
		}
		
		if(CharSequence.class.isInstance(target)) {
			if(StringUtils.isBlank((CharSequence) target)) {
				return null;
			}
			return DateUtil.parseLocalTime(target.toString());
		}
		
		if(Number.class.isInstance(target)) {
			return new java.util.Date(((Number)target).longValue()).toInstant().atZone(ZoneId.systemDefault()).toLocalTime();
		}
		throw new OrmRuntimeException(String.format("未支持从%s类型转为%s类型", target.getClass().getName(), LocalTime.class.getName()));
	}		
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy