package io.github.greyp9.arwo.core.date.test;

import io.github.greyp9.arwo.core.date.DateU;
import io.github.greyp9.arwo.core.date.DurationU;
import io.github.greyp9.arwo.core.date.XsdDateU;
import org.junit.Assert;
import org.junit.Test;

import java.util.Date;

public class DurationSinceTest {

    @Test
    public void testDurationSinceOneDay() {
        final Date date = new Date();
        final long elapsed = DurationU.Const.ONE_DAY_MILLIS;
        final Date dateBefore = new Date(date.getTime() - elapsed);
        final String duration = DurationU.duration(dateBefore, date);
        //Assert.assertEquals("P1D", duration);
    }

    @Test
    public void testDurationSinceThirtyDays() throws Exception {
        final Date date = new Date();
        final long elapsed = DurationU.Const.ONE_DAY_MILLIS * 28;
        final Date dateBefore = new Date(date.getTime() - elapsed);
        final String duration = DurationU.duration(dateBefore, date);
        Assert.assertEquals("P28D", duration);
    }

    @Test
    public void testDurationSubtractP1Y() throws Exception {
        final Date date = XsdDateU.fromXSDZ("2000-01-01T00:00:00.000Z");
        final Date dateBefore = DurationU.subtract(date, DateU.Const.TZ_GMT, "P1Y");
        Assert.assertEquals("1999-01-01T00:00:00.000Z", XsdDateU.toXSDZMillis(dateBefore));
    }

    @Test
    public void testDurationSubtractP1M() throws Exception {
        final Date date = XsdDateU.fromXSDZ("2000-01-01T00:00:00.000Z");
        final Date dateBefore = DurationU.subtract(date, DateU.Const.TZ_GMT, "P1M");
        Assert.assertEquals("1999-12-01T00:00:00.000Z", XsdDateU.toXSDZMillis(dateBefore));
    }

    @Test
    public void testDurationSubtractP1D() throws Exception {
        final Date date = XsdDateU.fromXSDZ("2000-01-01T00:00:00.000Z");
        final Date dateBefore = DurationU.subtract(date, DateU.Const.TZ_GMT, "P1D");
        Assert.assertEquals("1999-12-31T00:00:00.000Z", XsdDateU.toXSDZMillis(dateBefore));
    }

    @Test
    public void testDurationSubtractP1Y1M1D() throws Exception {
        final Date date = XsdDateU.fromXSDZ("2000-01-01T00:00:00.000Z");
        final Date dateBefore = DurationU.subtract(date, DateU.Const.TZ_GMT, "P1Y1M1D");
        Assert.assertEquals("1998-11-30T00:00:00.000Z", XsdDateU.toXSDZMillis(dateBefore));
    }

    @Test
    public void testDurationSubtractP365D() throws Exception {
        final Date date = XsdDateU.fromXSDZ("2000-01-01T00:00:00.000Z");
        final Date dateBefore = DurationU.subtract(date, DateU.Const.TZ_GMT, "P1Y");
        Assert.assertEquals("1999-01-01T00:00:00.000Z", XsdDateU.toXSDZMillis(dateBefore));
    }
}

@@ -210,16 +210,41 @@
 Assert;%0A
+import org.junit.Before;%0A
 import o
@@ -286,41 +286,244 @@
 te;%0A
-%0Apublic class DurationSinceTest %7B
+import java.util.logging.Logger;%0A%0Apublic class DurationSinceTest %7B%0A    private final Logger logger = Logger.getLogger(getClass().getName());%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        logger.finest(%22setUp()%22);%0A    %7D
 %0A%0A  
@@ -823,10 +823,8 @@
     
-//
 Asse
@@ -912,36 +912,22 @@
 nceT
-hirtyDays() throws Exception
+wentyOneDays()
  %7B%0A 
@@ -955,32 +955,84 @@
 e = new Date();%0A
+        logger.finest(XsdDateU.toXSDZMillis(date));%0A
         final lo
@@ -1078,17 +1078,17 @@
 LLIS * 2
-8
+1
 ;%0A      
@@ -1141,32 +1141,90 @@
 e() - elapsed);%0A
+        logger.finest(XsdDateU.toXSDZMillis(dateBefore));%0A
         final St
@@ -1308,17 +1308,17 @@
 uals(%22P2
-8
+1
 D%22, dura
@@ -1382,33 +1382,16 @@
 actP1Y()
- throws Exception
  %7B%0A     
@@ -1693,33 +1693,16 @@
 actP1M()
- throws Exception
  %7B%0A     
@@ -2004,33 +2004,16 @@
 actP1D()
- throws Exception
  %7B%0A     
@@ -2319,33 +2319,16 @@
 1Y1M1D()
- throws Exception
  %7B%0A     
@@ -2636,33 +2636,16 @@
 tP365D()
- throws Exception
  %7B%0A     

fix broken test