package com.wsm.common.util;

import java.util.Date;

import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class DateTimeUtils {
	
	public static String getStatusByTime(String openTime) {
		try {
			
			String[] times = openTime.split(" - ");
			DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");  
			
			DateTime start = new DateTime(times[0]);    
			DateTime end = DateTime.parse(times[1] + " 23:59:59", format);
			if(start.isAfterNow()){
				return "待展出";
			}else if(start.isEqualNow() || (start.isBeforeNow() && end.isAfterNow()) || end.isEqualNow()){
				return "展出中";
			}else if (end.isBeforeNow()){
				return "已结束";
			}
		}catch(Exception e){
			return "";
		}
		return "";
	}
	
	public static String getStatusByDate(Date startTime, Date endTime) {
		try {
			
			DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");  
			
			DateTime start = new DateTime(startTime);    
			DateTime end = DateTime.parse(endTime + " 23:59:59", format);
			if(start.isAfterNow()){
				return "待展出";
			}else if(start.isEqualNow() || (start.isBeforeNow() && end.isAfterNow()) || end.isEqualNow()){
				return "展出中";
			}else if (end.isBeforeNow()){
				return "已结束";
			}
		}catch(Exception e){
			return "";
		}
		return "";
	}
	
	public static String getStatusTextByDate(Date startTime, Date endTime) {
		try {
			if (startTime == null && endTime == null){
				return "常设展";
			}
			DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");  
			
			DateTime start = new DateTime(startTime);    
			DateTime end = DateTime.parse(endTime + " 23:59:59", format);
			if(start.isAfterNow()){
				Duration duration = new Duration(DateTime.now(), start);
				return duration.getStandardDays() + 1 + "天后开幕";
			}else if(start.isEqualNow() || (start.isBeforeNow() && end.isAfterNow()) || end.isEqualNow()){
				Duration duration = new Duration(DateTime.now(), end);
				return duration.getStandardDays() + "天后闭幕";
			}else if (end.isBeforeNow()){
				return "已结束";
			}
		}catch(Exception e){
			return "";
		}
		return "常设展";
	}

}
