2019-02-26 20:38:27 +01:00
|
|
|
package info.nightscout.androidaps.utils;
|
2017-11-20 13:34:13 +01:00
|
|
|
|
|
|
|
|
2018-04-01 18:44:58 +02:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Before;
|
2017-11-20 13:34:13 +01:00
|
|
|
import org.junit.Test;
|
2018-04-01 18:44:58 +02:00
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
|
|
import org.powermock.modules.junit4.PowerMockRunner;
|
2017-11-20 13:34:13 +01:00
|
|
|
|
2017-12-22 02:55:40 +01:00
|
|
|
import java.util.Date;
|
|
|
|
|
2018-04-01 18:44:58 +02:00
|
|
|
import info.AAPSMocker;
|
|
|
|
import info.nightscout.androidaps.MainApp;
|
|
|
|
|
2017-12-22 02:55:40 +01:00
|
|
|
import static org.junit.Assert.assertEquals;
|
2018-04-01 18:44:58 +02:00
|
|
|
import static org.junit.Assert.assertTrue;
|
2017-11-20 13:34:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mike on 20.11.2017.
|
|
|
|
*/
|
2018-04-01 18:44:58 +02:00
|
|
|
@RunWith(PowerMockRunner.class)
|
2018-04-02 10:29:19 +02:00
|
|
|
@PrepareForTest({MainApp.class})
|
2017-11-20 13:34:13 +01:00
|
|
|
public class DateUtilTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void fromISODateStringTest() throws Exception {
|
2017-12-22 02:55:40 +01:00
|
|
|
assertEquals(1511124634417L, DateUtil.fromISODateString("2017-11-19T22:50:34.417+0200").getTime());
|
|
|
|
assertEquals(1511124634000L, DateUtil.fromISODateString("2017-11-19T22:50:34+0200").getTime());
|
|
|
|
assertEquals(1512317365000L, DateUtil.fromISODateString("2017-12-03T16:09:25.000Z").getTime());
|
|
|
|
assertEquals(1513902750000L, DateUtil.fromISODateString("2017-12-22T00:32:30Z").getTime());
|
2017-11-20 13:34:13 +01:00
|
|
|
}
|
|
|
|
|
2017-12-22 02:55:40 +01:00
|
|
|
@Test
|
|
|
|
public void toISOStringTest() throws Exception {
|
|
|
|
assertEquals("2017-12-22T00:32:30Z", DateUtil.toISOString(new Date(1513902750000L)));
|
2018-04-01 18:44:58 +02:00
|
|
|
assertEquals("2017-12-22T00:32:30Z", DateUtil.toISOString(1513902750000L));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void toDateTest() {
|
|
|
|
assertTrue(DateUtil.toDate((int) (T.hours(1).secs() + T.mins(1).secs() + 1)).toString().contains("01:01:00"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void toSecondsTest() {
|
|
|
|
Assert.assertEquals(3600, DateUtil.toSeconds("01:00"));
|
|
|
|
Assert.assertEquals(3600, DateUtil.toSeconds("01:00 a.m."));
|
|
|
|
Assert.assertEquals(3600, DateUtil.toSeconds("01:00 AM"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dateStringTest() {
|
|
|
|
assertTrue(DateUtil.dateString(new Date(1513902750000L)).contains("22"));
|
|
|
|
assertTrue(DateUtil.dateString(1513902750000L).contains("22"));
|
2017-12-22 02:55:40 +01:00
|
|
|
}
|
2017-11-20 13:34:13 +01:00
|
|
|
|
2018-04-01 18:44:58 +02:00
|
|
|
@Test
|
|
|
|
public void timeStringTest() {
|
2018-04-01 20:02:22 +02:00
|
|
|
assertTrue(DateUtil.timeString(new Date(1513902750000L)).contains("32"));
|
|
|
|
assertTrue(DateUtil.timeString(1513902750000L).contains("32"));
|
2018-04-01 18:44:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dateAndTimeStringTest() {
|
|
|
|
assertTrue(DateUtil.dateAndTimeString(1513902750000L).contains("22"));
|
2018-04-01 20:02:22 +02:00
|
|
|
assertTrue(DateUtil.dateAndTimeString(1513902750000L).contains("32"));
|
2018-04-01 18:44:58 +02:00
|
|
|
assertTrue(DateUtil.dateAndTimeString(new Date(1513902750000L)).contains("22"));
|
2018-04-01 20:02:22 +02:00
|
|
|
assertTrue(DateUtil.dateAndTimeString(new Date(1513902750000L)).contains("32"));
|
2018-04-01 18:44:58 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 19:52:01 +02:00
|
|
|
@Test
|
|
|
|
public void dateAndTimeRangeStringTest() {
|
|
|
|
assertTrue(DateUtil.dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22"));
|
|
|
|
assertTrue(DateUtil.dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32"));
|
|
|
|
assertTrue(DateUtil.dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22"));
|
|
|
|
assertTrue(DateUtil.dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32"));
|
|
|
|
}
|
|
|
|
|
2018-04-01 18:44:58 +02:00
|
|
|
@Test
|
|
|
|
public void timeStringFromSecondsTest() {
|
|
|
|
Assert.assertEquals("1:00 AM", DateUtil.timeStringFromSeconds((int) T.hours(1).secs()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void timeFrameStringTest() {
|
|
|
|
Assert.assertEquals("(1h 1')", DateUtil.timeFrameString((T.hours(1).msecs() + T.mins(1).msecs())));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void prepareMock() {
|
|
|
|
AAPSMocker.mockMainApp();
|
|
|
|
AAPSMocker.mockStrings();
|
|
|
|
}
|
2017-11-20 13:34:13 +01:00
|
|
|
}
|