package com.conveyal.r5.profile;

import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.*;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.Date;

import static org.junit.Assert.*;

/**
 * Add some date time related tests for profile reques
 *
 * Created by mabu on 2.12.2015.
 */
public class ProfileRequestTest {

    private static final Logger LOG = LoggerFactory.getLogger(ProfileRequestTest.class);

    static ProfileRequest profileRequest;

    @Before
    public void setUp() throws Exception {
        profileRequest = new ProfileRequest();

        profileRequest.setZoneId(ZoneId.of("Europe/Ljubljana"));


    }

    @Test
    public void testEmptyGetFromTimeDate() throws Exception {


        //FIXME: this actually returns yesterday:23:00 as time and date
        //To fix or not to fix depends on #37
        Instant expected = ZonedDateTime.now(profileRequest.getZoneId()).truncatedTo(ChronoUnit.DAYS).toInstant();
        Instant got = Instant.ofEpochMilli(profileRequest.getFromTimeDate());

        assertEquals(expected, got);

    }

    @Test
    public void testEmptyDate() throws Exception {
        profileRequest.fromTime = 4*3600;



        Instant expected = ZonedDateTime.now(profileRequest.getZoneId()).truncatedTo(ChronoUnit.HOURS).withHour(4).toInstant();
        Instant got = Instant.ofEpochMilli(profileRequest.getFromTimeDate());

        LOG.info("Expected:{} got:{}", expected, got);

        assertEquals(expected, got);

    }

    @Test
    public void testEmptyFromTime() throws Exception {

        profileRequest.date = new org.joda.time.LocalDate(2015,10,5);

        Instant expected = ZonedDateTime.of(2015, 10, 5,0,0,0,0,profileRequest.getZoneId()).toInstant();
        Instant got = Instant.ofEpochMilli(profileRequest.getFromTimeDate());

        assertEquals(expected, got);

    }

    @Test
    public void testFull() throws Exception {

        profileRequest.date = new org.joda.time.LocalDate(2015,1,5);
        profileRequest.fromTime = 6*3600+22*60;

        Instant expected = ZonedDateTime.of(2015,1,5,6,22,0,0,profileRequest.getZoneId()).toInstant();
        Instant got = Instant.ofEpochMilli(profileRequest.getFromTimeDate());

        assertEquals(expected, got);

    }
}
@@ -301,13 +301,9 @@
 %0A * 
-Add s
+S
 ome 
@@ -307,16 +307,20 @@
 me date 
+and 
 time rel
@@ -348,19 +348,19 @@
 e reques
-%0A *
+ts.
 %0A * Crea
@@ -659,17 +659,16 @@
 uest();%0A
-%0A
         
@@ -724,18 +724,16 @@
 ana%22));%0A
-%0A%0A
     %7D%0A%0A 
@@ -803,18 +803,16 @@
 ption %7B%0A
-%0A%0A
         
@@ -1106,33 +1106,32 @@
 romTimeDate());%0A
-%0A
         assertEq
@@ -1143,33 +1143,32 @@
 expected, got);%0A
-%0A
     %7D%0A%0A    @Test
@@ -1261,19 +1261,16 @@
 4*3600;%0A
-%0A%0A%0A
         
@@ -1459,33 +1459,32 @@
 romTimeDate());%0A
-%0A
         LOG.info
@@ -1518,25 +1518,24 @@
 cted, got);%0A
-%0A
         asse
@@ -1551,33 +1551,32 @@
 expected, got);%0A
-%0A
     %7D%0A%0A    @Test
@@ -1623,33 +1623,32 @@
 ows Exception %7B%0A
-%0A
         profileR
@@ -1661,34 +1661,16 @@
 .date = 
-new org.joda.time.
 LocalDat
@@ -1666,24 +1666,27 @@
  = LocalDate
+.of
 (2015,10,5);
@@ -1686,17 +1686,16 @@
 ,10,5);%0A
-%0A
         
@@ -1861,33 +1861,32 @@
 romTimeDate());%0A
-%0A
         assertEq
@@ -1902,25 +1902,24 @@
 cted, got);%0A
-%0A
     %7D%0A%0A    @
@@ -1969,17 +1969,16 @@
 ption %7B%0A
-%0A
         
@@ -2003,26 +2003,8 @@
 e = 
-new org.joda.time.
 Loca
@@ -2008,16 +2008,19 @@
 ocalDate
+.of
 (2015,1,
@@ -2071,17 +2071,16 @@
 +22*60;%0A
-%0A
         
@@ -2252,17 +2252,16 @@
 ate());%0A
-%0A
         
@@ -2289,16 +2289,15 @@
 , got);%0A
-%0A
     %7D%0A%7D

remove usage of Joda time library