package com.yuzhouwan.hacker.joda;

import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;

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

import static org.junit.Assert.assertEquals;

/**
 * Copyright @ 2017 yuzhouwan.com
 * All right reserved.
 * Function: Joda Time Have a Try
 *
 * @author Benedict Jin
 * @since 2015/8/20
 */
public class JodaTimeHaveATry {

    private static Date date;

    @Before
    public void before() {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hh:mm:ss");
        try {
            date = sdf.parse("2015-08-12-11:20:38");
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void test() {

        DateTime jodaTime = new DateTime(date);

        assertEquals(2015, jodaTime.getYear());
        assertEquals(20, jodaTime.getMinuteOfHour());

        assertEquals("八月", jodaTime.monthOfYear().getAsShortText());
    }

    /**
     * 当前时间减少 月 or 天 ...
     */
    @Test
    public void minusTest() {

        for (int i = 0; i < 5; i++) {
            System.out.println(DateTime.now().minusMonths(i).toString("yyyyMMdd HH:mm:ss"));
            System.out.println(DateTime.now().minusDays(i).toString("yyyyMMdd HH:mm:ss"));
            System.out.println("-----------------------------");
        }
    }

    @Test
    public void longTest() {
        assertEquals("Sun May 28 11:15:14 CST 2017", new Date(Long.valueOf("1495941314418")).toString());
        assertEquals("2017-05-28T11:15:14.418+08:00", new DateTime(Long.valueOf("1495941314418")).toString());
        assertEquals("2017-05-28T11:16:14.418+08:00",
                new DateTime(Long.valueOf("1495941314418")).plusMillis(Integer.valueOf(60000L + "")).toString());
    }
}

@@ -1655,52 +1655,243 @@
     
-assertEquals(%222017-05-28T11:16:14.418+08:00%22
+DateTime afterOneMinter = new DateTime(Long.valueOf(%221495941314418%22)).plusMillis(Integer.valueOf(60000L + %22%22));%0A        assertEquals(%222017-05-28T11:16:14.418+08:00%22,%0A                afterOneMinter.toString());%0A        assertEquals(true
 ,%0A  
@@ -1930,34 +1930,34 @@
 valueOf(%22149
-5941314418
+6384856085
 %22)).plusMill
@@ -1988,26 +1988,93 @@
 L + %22%22))
-.toString(
+%0A                        .isAfter(new DateTime(Long.valueOf(%221496384820000%22))
 ));%0A    

Improve JodaTime testcase