package cn.freemud.utils;

import cn.freemud.base.util.DateUtil;
import org.apache.commons.lang.time.DateUtils;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtilsTest {


    @Test
   public void testDateCompare() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1 = sdf.parse("2020-12-30 00:00:00");
        Date date2 = sdf.parse("2020-12-14 11:50:00");

        System.out.println("date1 : " + sdf.format(date1));
        System.out.println("date2 : " + sdf.format(date2));
        System.out.println(date1.compareTo(date2));
        if (date1.compareTo(date2) > 0) {
            System.out.println("Date1 时间在 Date2 之后");
        } else if (date1.compareTo(date2) < 0) {
            System.out.println("Date1 时间在 Date2 之前");
        } else if (date1.compareTo(date2) == 0) {
            System.out.println("Date1 时间与 Date2 相等");
        } else {
            System.out.println("程序怎么会运行到这里?正常应该不会");
        }

         boolean x =(DateUtils.addMinutes(new Date(), 45).compareTo(date2) <= 0);
        System.out.println(x);
    }

    @Test
    public  void  testBefore() throws ParseException {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1 = sdf.parse("2020-12-30 00:00:00");
        Date date = DateUtil.setEndDay(new Date());
        String s = DateUtil.convert2String(date, "yyyy-MM-dd HH:mm:ss");
        System.out.println(date.before(date1));
    }
}
