package com.dev.swms.server.action.formatter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.dev.energy.server.format.Formatter;
import com.dev.swms.server.model.base.Item;

public class DaysoutofdateFormatter implements Formatter{

	@Override
	public String format(String property, Object storageDate, List origenData,
			String referenceModel, String locale) {
			String type=storageDate.toString();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar calendar=Calendar.getInstance();
			
			String gqDate = String.valueOf(origenData.get(26));//过期日期
			if(gqDate.equals("-")){
				return null;
			}
			String newDate=sdf.format(new Date());//当前时间
			String yxq = String.valueOf(origenData.get(11));//有效期
			try {
				calendar.setTime(sdf.parse(gqDate)); 
				long time1 = calendar.getTimeInMillis();   
				calendar.setTime(sdf.parse(newDate)); 
				long time2 = calendar.getTimeInMillis();      
				long day=(time1-time2)/(1000*3600*24);
				String days = String.valueOf(day); 
				if(Integer.parseInt(days)<=0){
					return "<div  >" + "已过期" + "</div>";
				}else{
					return "<div  >" + days + "</div>";
				}
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return type;
		} 
			 
			
			
			
	

}
