mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Show bar chart with monthly totals
This commit is contained in:
@@ -404,4 +404,37 @@ public abstract class CheckmarkList
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<Checkmark> groupBy(DateUtils.TruncateField field)
|
||||
{
|
||||
Repetition oldest = habit.getRepetitions().getOldest();
|
||||
if(oldest == null) return new ArrayList<>();
|
||||
List<Checkmark> checks = getByInterval(oldest.getTimestamp(), DateUtils.getToday());
|
||||
|
||||
int count = 0;
|
||||
Timestamp truncatedTimestamps[] = new Timestamp[checks.size()];
|
||||
int values[] = new int[checks.size()];
|
||||
|
||||
for (Checkmark rep : checks)
|
||||
{
|
||||
Timestamp tt = rep.getTimestamp().truncate(field);
|
||||
if (count == 0 || !truncatedTimestamps[count - 1].equals(tt))
|
||||
truncatedTimestamps[count++] = tt;
|
||||
|
||||
if(habit.isNumerical())
|
||||
values[count - 1] += rep.getValue();
|
||||
else if(rep.getValue() == Checkmark.CHECKED_EXPLICITLY)
|
||||
values[count - 1] += 1000;
|
||||
}
|
||||
|
||||
ArrayList<Checkmark> groupedCheckmarks = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Checkmark rep = new Checkmark(truncatedTimestamps[i], values[i]);
|
||||
groupedCheckmarks.add(rep);
|
||||
}
|
||||
|
||||
return groupedCheckmarks;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,12 @@
|
||||
package org.isoron.uhabits.core.models;
|
||||
|
||||
import org.apache.commons.lang3.builder.*;
|
||||
import org.isoron.uhabits.core.utils.DateFormats;
|
||||
import org.isoron.uhabits.core.utils.DateUtils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||
|
||||
@@ -64,9 +70,9 @@ public final class Repetition
|
||||
Repetition that = (Repetition) o;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(timestamp, that.timestamp)
|
||||
.append(value, that.value)
|
||||
.isEquals();
|
||||
.append(timestamp, that.timestamp)
|
||||
.append(value, that.value)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
public Timestamp getTimestamp()
|
||||
@@ -83,17 +89,17 @@ public final class Repetition
|
||||
public int hashCode()
|
||||
{
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(timestamp)
|
||||
.append(value)
|
||||
.toHashCode();
|
||||
.append(timestamp)
|
||||
.append(value)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new ToStringBuilder(this, defaultToStringStyle())
|
||||
.append("timestamp", timestamp)
|
||||
.append("value", value)
|
||||
.toString();
|
||||
.append("timestamp", timestamp)
|
||||
.append("value", value)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public abstract class RepetitionList
|
||||
public HashMap<Timestamp, Integer[]> getWeekdayFrequency()
|
||||
{
|
||||
List<Repetition> reps =
|
||||
getByInterval(Timestamp.ZERO, DateUtils.getToday());
|
||||
getByInterval(Timestamp.ZERO, DateUtils.getToday());
|
||||
HashMap<Timestamp, Integer[]> map = new HashMap<>();
|
||||
|
||||
for (Repetition r : reps)
|
||||
@@ -187,7 +187,7 @@ public abstract class RepetitionList
|
||||
@NonNull
|
||||
public synchronized Repetition toggle(Timestamp timestamp)
|
||||
{
|
||||
if(habit.isNumerical())
|
||||
if (habit.isNumerical())
|
||||
throw new IllegalStateException("habit must NOT be numerical");
|
||||
|
||||
Repetition rep = getByTimestamp(timestamp);
|
||||
@@ -213,7 +213,7 @@ public abstract class RepetitionList
|
||||
public void toggle(Timestamp timestamp, int value)
|
||||
{
|
||||
Repetition rep = getByTimestamp(timestamp);
|
||||
if(rep != null) remove(rep);
|
||||
if (rep != null) remove(rep);
|
||||
add(new Repetition(timestamp, value));
|
||||
habit.invalidateNewerThan(timestamp);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
package org.isoron.uhabits.core.models;
|
||||
|
||||
import org.apache.commons.lang3.builder.*;
|
||||
import org.isoron.uhabits.core.utils.DateFormats;
|
||||
import org.isoron.uhabits.core.utils.DateUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -138,13 +140,16 @@ public final class Timestamp
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new ToStringBuilder(this, defaultToStringStyle())
|
||||
.append("unixTime", unixTime)
|
||||
.toString();
|
||||
return DateFormats.getCSVDateFormat().format(new Date(unixTime));
|
||||
}
|
||||
|
||||
public int getWeekday()
|
||||
{
|
||||
return toCalendar().get(DAY_OF_WEEK) % 7;
|
||||
}
|
||||
|
||||
public Timestamp truncate(DateUtils.TruncateField field)
|
||||
{
|
||||
return new Timestamp(DateUtils.truncate(field, unixTime));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.isoron.uhabits.core.utils.*;
|
||||
public class HabitFixtures
|
||||
{
|
||||
public boolean NON_DAILY_HABIT_CHECKS[] = {
|
||||
true, false, false, true, true, true, false, false, true, true
|
||||
true, false, false, true, true, true, false, false, true, true
|
||||
};
|
||||
|
||||
private final ModelFactory modelFactory;
|
||||
@@ -58,9 +58,9 @@ public class HabitFixtures
|
||||
habit.setColor(4);
|
||||
|
||||
Timestamp today = DateUtils.getToday();
|
||||
int marks[] = { 0, 1, 3, 5, 7, 8, 9, 10, 12, 14, 15, 17, 19, 20, 26, 27,
|
||||
28, 50, 51, 52, 53, 54, 58, 60, 63, 65, 70, 71, 72, 73, 74, 75, 80,
|
||||
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
|
||||
int marks[] = {0, 1, 3, 5, 7, 8, 9, 10, 12, 14, 15, 17, 19, 20, 26, 27,
|
||||
28, 50, 51, 52, 53, 54, 58, 60, 63, 65, 70, 71, 72, 73, 74, 75, 80,
|
||||
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
|
||||
|
||||
for (int mark : marks)
|
||||
habit.getRepetitions().toggle(today.minus(mark));
|
||||
@@ -81,10 +81,10 @@ public class HabitFixtures
|
||||
saveIfSQLite(habit);
|
||||
|
||||
Timestamp today = DateUtils.getToday();
|
||||
int times[] = { 0, 1, 3, 5, 7, 8, 9, 10 };
|
||||
int values[] = { 100, 200, 300, 400, 500, 600, 700, 800 };
|
||||
int times[] = {0, 1, 3, 5, 7, 8, 9, 10};
|
||||
int values[] = {100, 200, 300, 400, 500, 600, 700, 800};
|
||||
|
||||
for(int i = 0; i < times.length; i++)
|
||||
for (int i = 0; i < times.length; i++)
|
||||
{
|
||||
Timestamp timestamp = today.minus(times[i]);
|
||||
habit.getRepetitions().add(new Repetition(timestamp, values[i]));
|
||||
@@ -93,6 +93,42 @@ public class HabitFixtures
|
||||
return habit;
|
||||
}
|
||||
|
||||
public Habit createLongNumericalHabit(Timestamp reference)
|
||||
{
|
||||
Habit habit = modelFactory.buildHabit();
|
||||
habit.setType(Habit.NUMBER_HABIT);
|
||||
habit.setName("Walk");
|
||||
habit.setDescription("How many steps did you walk today?");
|
||||
habit.setUnit("steps");
|
||||
habit.setTargetType(Habit.AT_LEAST);
|
||||
habit.setTargetValue(100);
|
||||
habit.setColor(1);
|
||||
saveIfSQLite(habit);
|
||||
|
||||
int times[] = {0, 5, 9, 15, 17, 21, 23, 27, 28, 35, 41, 45, 47, 53, 56, 62, 70, 73, 78,
|
||||
83, 86, 94, 101, 106, 113, 114, 120, 126, 130, 133, 141, 143, 148, 151, 157, 164,
|
||||
166, 171, 173, 176, 179, 183, 191, 259, 264, 268, 270, 275, 282, 284, 289, 295,
|
||||
302, 306, 310, 315, 323, 325, 328, 335, 343, 349, 351, 353, 357, 359, 360, 367,
|
||||
372, 376, 380, 385, 393, 400, 404, 412, 415, 418, 422, 425, 433, 437, 444, 449,
|
||||
455, 460, 462, 465, 470, 471, 479, 481, 485, 489, 494, 495, 500, 501, 503, 507};
|
||||
|
||||
int values[] = {230, 306, 148, 281, 134, 285, 104, 158, 325, 236, 303, 210, 118, 124,
|
||||
301, 201, 156, 376, 347, 367, 396, 134, 160, 381, 155, 354, 231, 134, 164, 354,
|
||||
236, 398, 199, 221, 208, 397, 253, 276, 214, 341, 299, 221, 353, 250, 341, 168,
|
||||
374, 205, 182, 217, 297, 321, 104, 237, 294, 110, 136, 229, 102, 271, 250, 294,
|
||||
158, 319, 379, 126, 282, 155, 288, 159, 215, 247, 207, 226, 244, 158, 371, 219,
|
||||
272, 228, 350, 153, 356, 279, 394, 202, 213, 214, 112, 248, 139, 245, 165, 256,
|
||||
370, 187, 208, 231, 341, 312};
|
||||
|
||||
for (int i = 0; i < times.length; i++)
|
||||
{
|
||||
Timestamp timestamp = reference.minus(times[i]);
|
||||
habit.getRepetitions().add(new Repetition(timestamp, values[i]));
|
||||
}
|
||||
|
||||
return habit;
|
||||
}
|
||||
|
||||
public Habit createShortHabit()
|
||||
{
|
||||
Habit habit = modelFactory.buildHabit();
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.apache.commons.io.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.database.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.models.Timestamp;
|
||||
import org.isoron.uhabits.core.models.memory.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.core.test.*;
|
||||
@@ -92,20 +93,24 @@ public class BaseUnitTest
|
||||
DateUtils.setFixedLocalTime(null);
|
||||
}
|
||||
|
||||
public long timestamp(int year, int month, int day)
|
||||
public long unixTime(int year, int month, int day)
|
||||
{
|
||||
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
|
||||
cal.set(year, month, day, 0, 0, 0);
|
||||
return cal.getTimeInMillis();
|
||||
}
|
||||
|
||||
public long timestamp(int year, int month, int day, int hour, int minute)
|
||||
public long unixTime(int year, int month, int day, int hour, int minute)
|
||||
{
|
||||
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
|
||||
cal.set(year, month, day, hour, minute);
|
||||
return cal.getTimeInMillis();
|
||||
}
|
||||
|
||||
public Timestamp timestamp(int year, int month, int day) {
|
||||
return new Timestamp(unixTime(year, month, day));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothing()
|
||||
{
|
||||
|
||||
@@ -28,9 +28,15 @@ import java.util.*;
|
||||
|
||||
import nl.jqno.equalsverifier.*;
|
||||
|
||||
import static java.util.Calendar.JANUARY;
|
||||
import static java.util.Calendar.JULY;
|
||||
import static java.util.Calendar.JUNE;
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.isoron.uhabits.core.models.Checkmark.*;
|
||||
import static org.isoron.uhabits.core.utils.DateUtils.TruncateField.MONTH;
|
||||
import static org.isoron.uhabits.core.utils.DateUtils.TruncateField.QUARTER;
|
||||
import static org.isoron.uhabits.core.utils.DateUtils.TruncateField.YEAR;
|
||||
|
||||
public class CheckmarkListTest extends BaseUnitTest
|
||||
{
|
||||
@@ -360,13 +366,12 @@ public class CheckmarkListTest extends BaseUnitTest
|
||||
Timestamp t = Timestamp.ZERO.plus(100);
|
||||
Checkmark checkmark = new Checkmark(t, 2);
|
||||
assertThat(checkmark.toString(),
|
||||
equalTo("{timestamp: {unixTime: 8640000000}, value: 2}"));
|
||||
equalTo("{timestamp: 1970-04-11, value: 2}"));
|
||||
|
||||
CheckmarkList.Interval interval =
|
||||
new CheckmarkList.Interval(t, t.plus(1), t.plus(2));
|
||||
assertThat(interval.toString(), equalTo(
|
||||
"{begin: {unixTime: 8640000000}, center: {unixTime: 8726400000}," +
|
||||
" end: {unixTime: 8812800000}}"));
|
||||
"{begin: 1970-04-11, center: 1970-04-12, end: 1970-04-13}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -376,4 +381,30 @@ public class CheckmarkListTest extends BaseUnitTest
|
||||
EqualsVerifier.forClass(Timestamp.class).verify();
|
||||
EqualsVerifier.forClass(CheckmarkList.Interval.class).verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroupBy() throws Exception
|
||||
{
|
||||
Habit habit = fixtures.createLongNumericalHabit(timestamp(2014, JUNE, 1));
|
||||
CheckmarkList checkmarks = habit.getCheckmarks();
|
||||
|
||||
List<Checkmark> byMonth = checkmarks.groupBy(MONTH);
|
||||
assertThat(byMonth.size(), equalTo(25)); // from 2013-01-01 to 2015-01-01
|
||||
assertThat(byMonth.get(0), equalTo(new Checkmark(timestamp(2015, JANUARY, 1), 0)));
|
||||
assertThat(byMonth.get(6), equalTo(new Checkmark(timestamp(2014, JULY, 1), 0)));
|
||||
assertThat(byMonth.get(12), equalTo(new Checkmark(timestamp(2014, JANUARY, 1), 1706)));
|
||||
assertThat(byMonth.get(18), equalTo(new Checkmark(timestamp(2013, JULY, 1), 1379)));
|
||||
|
||||
List<Checkmark> byQuarter = checkmarks.groupBy(QUARTER);
|
||||
assertThat(byQuarter.size(), equalTo(9)); // from 2013-Q1 to 2015-Q1
|
||||
assertThat(byQuarter.get(0), equalTo(new Checkmark(timestamp(2015, JANUARY, 1), 0)));
|
||||
assertThat(byQuarter.get(4), equalTo(new Checkmark(timestamp(2014, JANUARY, 1), 4964)));
|
||||
assertThat(byQuarter.get(8), equalTo(new Checkmark(timestamp(2013, JANUARY, 1), 4975)));
|
||||
|
||||
List<Checkmark> byYear = checkmarks.groupBy(YEAR);
|
||||
assertThat(byYear.size(), equalTo(3)); // from 2013 to 2015
|
||||
assertThat(byYear.get(0), equalTo(new Checkmark(timestamp(2015, JANUARY, 1), 0)));
|
||||
assertThat(byYear.get(1), equalTo(new Checkmark(timestamp(2014, JANUARY, 1), 8227)));
|
||||
assertThat(byYear.get(2), equalTo(new Checkmark(timestamp(2013, JANUARY, 1), 16172)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +189,6 @@ public class RepetitionListTest extends BaseUnitTest
|
||||
public void testToString() throws Exception
|
||||
{
|
||||
Repetition rep = new Repetition(Timestamp.ZERO.plus(100), 20);
|
||||
assertThat(rep.toString(), equalTo("{timestamp: {unixTime: 8640000000}, value: 20}"));
|
||||
assertThat(rep.toString(), equalTo("{timestamp: 1970-04-11, value: 20}"));
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,6 @@ public class ScoreTest extends BaseUnitTest
|
||||
public void testToString() throws Exception
|
||||
{
|
||||
Score score = new Score(Timestamp.ZERO.plus(100), 150.0);
|
||||
assertThat(score.toString(), equalTo( "{timestamp: {unixTime: 8640000000}, value: 150.0}"));
|
||||
assertThat(score.toString(), equalTo( "{timestamp: 1970-04-11, value: 150.0}"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,6 @@ public class StreakListTest extends BaseUnitTest
|
||||
Timestamp time = Timestamp.ZERO.plus(100);
|
||||
Streak streak = new Streak(time, time.plus(10));
|
||||
assertThat(streak.toString(), equalTo(
|
||||
"{start: {unixTime: 8640000000}, end: {unixTime: 9504000000}}"));
|
||||
"{start: 1970-04-11, end: 1970-04-21}"));
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
||||
@Test
|
||||
public void testScheduleAll()
|
||||
{
|
||||
long now = timestamp(2015, 1, 26, 13, 0);
|
||||
long now = unixTime(2015, 1, 26, 13, 0);
|
||||
DateUtils.setFixedLocalTime(now);
|
||||
|
||||
Habit h1 = fixtures.createEmptyHabit();
|
||||
@@ -72,9 +72,9 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
||||
|
||||
reminderScheduler.scheduleAll();
|
||||
|
||||
verify(sys).scheduleShowReminder(eq(timestamp(2015, 1, 27, 12, 30)),
|
||||
verify(sys).scheduleShowReminder(eq(unixTime(2015, 1, 27, 12, 30)),
|
||||
eq(h1), anyLong());
|
||||
verify(sys).scheduleShowReminder(eq(timestamp(2015, 1, 26, 22, 30)),
|
||||
verify(sys).scheduleShowReminder(eq(unixTime(2015, 1, 26, 22, 30)),
|
||||
eq(h2), anyLong());
|
||||
Mockito.verifyNoMoreInteractions(sys);
|
||||
}
|
||||
@@ -82,8 +82,8 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
||||
@Test
|
||||
public void testSchedule_atSpecificTime()
|
||||
{
|
||||
long atTime = timestamp(2015, 1, 30, 11, 30);
|
||||
long expectedCheckmarkTime = timestamp(2015, 1, 30, 0, 0);
|
||||
long atTime = unixTime(2015, 1, 30, 11, 30);
|
||||
long expectedCheckmarkTime = unixTime(2015, 1, 30, 0, 0);
|
||||
|
||||
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
|
||||
scheduleAndVerify(atTime, expectedCheckmarkTime, atTime);
|
||||
@@ -92,11 +92,11 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
||||
@Test
|
||||
public void testSchedule_laterToday()
|
||||
{
|
||||
long now = timestamp(2015, 1, 26, 6, 30);
|
||||
long now = unixTime(2015, 1, 26, 6, 30);
|
||||
DateUtils.setFixedLocalTime(now);
|
||||
|
||||
long expectedCheckmarkTime = timestamp(2015, 1, 26, 0, 0);
|
||||
long expectedReminderTime = timestamp(2015, 1, 26, 12, 30);
|
||||
long expectedCheckmarkTime = unixTime(2015, 1, 26, 0, 0);
|
||||
long expectedReminderTime = unixTime(2015, 1, 26, 12, 30);
|
||||
|
||||
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
|
||||
scheduleAndVerify(null, expectedCheckmarkTime, expectedReminderTime);
|
||||
@@ -105,11 +105,11 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
||||
@Test
|
||||
public void testSchedule_tomorrow()
|
||||
{
|
||||
long now = timestamp(2015, 1, 26, 13, 0);
|
||||
long now = unixTime(2015, 1, 26, 13, 0);
|
||||
DateUtils.setFixedLocalTime(now);
|
||||
|
||||
long expectedCheckmarkTime = timestamp(2015, 1, 27, 0, 0);
|
||||
long expectedReminderTime = timestamp(2015, 1, 27, 12, 30);
|
||||
long expectedCheckmarkTime = unixTime(2015, 1, 27, 0, 0);
|
||||
long expectedReminderTime = unixTime(2015, 1, 27, 12, 30);
|
||||
|
||||
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
|
||||
scheduleAndVerify(null, expectedCheckmarkTime, expectedReminderTime);
|
||||
@@ -122,7 +122,7 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
||||
Mockito.verifyZeroInteractions(sys);
|
||||
}
|
||||
|
||||
public long timestamp(int year, int month, int day, int hour, int minute)
|
||||
public long unixTime(int year, int month, int day, int hour, int minute)
|
||||
{
|
||||
Calendar cal = DateUtils.getStartOfTodayCalendar();
|
||||
cal.set(year, month, day, hour, minute);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class DateUtilsTest extends BaseUnitTest
|
||||
@Test
|
||||
public void testFormatHeaderDate()
|
||||
{
|
||||
long timestamp = timestamp(2015, DECEMBER, 31);
|
||||
long timestamp = unixTime(2015, DECEMBER, 31);
|
||||
GregorianCalendar date = new Timestamp(timestamp).toCalendar();
|
||||
String formatted = DateUtils.formatHeaderDate(date);
|
||||
assertThat(formatted, equalTo("Thu\n31"));
|
||||
@@ -56,19 +56,19 @@ public class DateUtilsTest extends BaseUnitTest
|
||||
{
|
||||
DateUtils.TruncateField field = DateUtils.TruncateField.WEEK_NUMBER;
|
||||
|
||||
long expected = timestamp(2015, Calendar.JANUARY, 11);
|
||||
long t0 = timestamp(2015, Calendar.JANUARY, 11);
|
||||
long t1 = timestamp(2015, Calendar.JANUARY, 16);
|
||||
long t2 = timestamp(2015, Calendar.JANUARY, 17);
|
||||
long expected = unixTime(2015, Calendar.JANUARY, 11);
|
||||
long t0 = unixTime(2015, Calendar.JANUARY, 11);
|
||||
long t1 = unixTime(2015, Calendar.JANUARY, 16);
|
||||
long t2 = unixTime(2015, Calendar.JANUARY, 17);
|
||||
|
||||
assertThat(DateUtils.truncate(field, t0), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t1), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t2), equalTo(expected));
|
||||
|
||||
expected = timestamp(2015, Calendar.JANUARY, 18);
|
||||
t0 = timestamp(2015, Calendar.JANUARY, 18);
|
||||
t1 = timestamp(2015, Calendar.JANUARY, 19);
|
||||
t2 = timestamp(2015, Calendar.JANUARY, 24);
|
||||
expected = unixTime(2015, Calendar.JANUARY, 18);
|
||||
t0 = unixTime(2015, Calendar.JANUARY, 18);
|
||||
t1 = unixTime(2015, Calendar.JANUARY, 19);
|
||||
t2 = unixTime(2015, Calendar.JANUARY, 24);
|
||||
|
||||
assertThat(DateUtils.truncate(field, t0), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t1), equalTo(expected));
|
||||
@@ -78,10 +78,10 @@ public class DateUtilsTest extends BaseUnitTest
|
||||
@Test
|
||||
public void testTruncate_month()
|
||||
{
|
||||
long expected = timestamp(2016, Calendar.JUNE, 1);
|
||||
long t0 = timestamp(2016, Calendar.JUNE, 1);
|
||||
long t1 = timestamp(2016, Calendar.JUNE, 15);
|
||||
long t2 = timestamp(2016, Calendar.JUNE, 20);
|
||||
long expected = unixTime(2016, Calendar.JUNE, 1);
|
||||
long t0 = unixTime(2016, Calendar.JUNE, 1);
|
||||
long t1 = unixTime(2016, Calendar.JUNE, 15);
|
||||
long t2 = unixTime(2016, Calendar.JUNE, 20);
|
||||
|
||||
DateUtils.TruncateField field = DateUtils.TruncateField.MONTH;
|
||||
|
||||
@@ -89,10 +89,10 @@ public class DateUtilsTest extends BaseUnitTest
|
||||
assertThat(DateUtils.truncate(field, t1), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t2), equalTo(expected));
|
||||
|
||||
expected = timestamp(2016, DECEMBER, 1);
|
||||
t0 = timestamp(2016, DECEMBER, 1);
|
||||
t1 = timestamp(2016, DECEMBER, 15);
|
||||
t2 = timestamp(2016, DECEMBER, 31);
|
||||
expected = unixTime(2016, DECEMBER, 1);
|
||||
t0 = unixTime(2016, DECEMBER, 1);
|
||||
t1 = unixTime(2016, DECEMBER, 15);
|
||||
t2 = unixTime(2016, DECEMBER, 31);
|
||||
|
||||
assertThat(DateUtils.truncate(field, t0), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t1), equalTo(expected));
|
||||
@@ -104,19 +104,19 @@ public class DateUtilsTest extends BaseUnitTest
|
||||
{
|
||||
DateUtils.TruncateField field = DateUtils.TruncateField.QUARTER;
|
||||
|
||||
long expected = timestamp(2016, JANUARY, 1);
|
||||
long t0 = timestamp(2016, JANUARY, 20);
|
||||
long t1 = timestamp(2016, FEBRUARY, 15);
|
||||
long t2 = timestamp(2016, MARCH, 30);
|
||||
long expected = unixTime(2016, JANUARY, 1);
|
||||
long t0 = unixTime(2016, JANUARY, 20);
|
||||
long t1 = unixTime(2016, FEBRUARY, 15);
|
||||
long t2 = unixTime(2016, MARCH, 30);
|
||||
|
||||
assertThat(DateUtils.truncate(field, t0), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t1), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t2), equalTo(expected));
|
||||
|
||||
expected = timestamp(2016, APRIL, 1);
|
||||
t0 = timestamp(2016, APRIL, 1);
|
||||
t1 = timestamp(2016, MAY, 30);
|
||||
t2 = timestamp(2016, JUNE, 20);
|
||||
expected = unixTime(2016, APRIL, 1);
|
||||
t0 = unixTime(2016, APRIL, 1);
|
||||
t1 = unixTime(2016, MAY, 30);
|
||||
t2 = unixTime(2016, JUNE, 20);
|
||||
|
||||
assertThat(DateUtils.truncate(field, t0), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t1), equalTo(expected));
|
||||
@@ -128,19 +128,19 @@ public class DateUtilsTest extends BaseUnitTest
|
||||
{
|
||||
DateUtils.TruncateField field = DateUtils.TruncateField.YEAR;
|
||||
|
||||
long expected = timestamp(2016, JANUARY, 1);
|
||||
long t0 = timestamp(2016, JANUARY, 1);
|
||||
long t1 = timestamp(2016, FEBRUARY, 25);
|
||||
long t2 = timestamp(2016, DECEMBER, 31);
|
||||
long expected = unixTime(2016, JANUARY, 1);
|
||||
long t0 = unixTime(2016, JANUARY, 1);
|
||||
long t1 = unixTime(2016, FEBRUARY, 25);
|
||||
long t2 = unixTime(2016, DECEMBER, 31);
|
||||
|
||||
assertThat(DateUtils.truncate(field, t0), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t1), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t2), equalTo(expected));
|
||||
|
||||
expected = timestamp(2017, JANUARY, 1);
|
||||
t0 = timestamp(2017, JANUARY, 1);
|
||||
t1 = timestamp(2017, MAY, 30);
|
||||
t2 = timestamp(2017, DECEMBER, 31);
|
||||
expected = unixTime(2017, JANUARY, 1);
|
||||
t0 = unixTime(2017, JANUARY, 1);
|
||||
t1 = unixTime(2017, MAY, 30);
|
||||
t2 = unixTime(2017, DECEMBER, 31);
|
||||
|
||||
assertThat(DateUtils.truncate(field, t0), equalTo(expected));
|
||||
assertThat(DateUtils.truncate(field, t1), equalTo(expected));
|
||||
@@ -150,10 +150,10 @@ public class DateUtilsTest extends BaseUnitTest
|
||||
@Test
|
||||
public void testMillisecondsUntilTomorrow() throws Exception
|
||||
{
|
||||
DateUtils.setFixedLocalTime(timestamp(2017, JANUARY, 1, 2, 59));
|
||||
DateUtils.setFixedLocalTime(unixTime(2017, JANUARY, 1, 2, 59));
|
||||
assertThat(DateUtils.millisecondsUntilTomorrow(), equalTo(60000L));
|
||||
|
||||
DateUtils.setFixedLocalTime(timestamp(2017, JANUARY, 1, 23, 0));
|
||||
DateUtils.setFixedLocalTime(unixTime(2017, JANUARY, 1, 23, 0));
|
||||
assertThat(DateUtils.millisecondsUntilTomorrow(), equalTo(14400000L));
|
||||
|
||||
}
|
||||
@@ -162,81 +162,81 @@ public class DateUtilsTest extends BaseUnitTest
|
||||
public void test_applyTimezone()
|
||||
{
|
||||
DateUtils.setFixedTimeZone(TimeZone.getTimeZone("Australia/Sydney"));
|
||||
assertEquals(applyTimezone(timestamp(2017, JULY, 30, 18, 0)), (timestamp(2017, JULY, 30, 8, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, SEPTEMBER, 30, 0, 0)), (timestamp(2017, SEPTEMBER, 29, 14, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, SEPTEMBER, 30, 10, 0)), (timestamp(2017, SEPTEMBER, 30, 0, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, SEPTEMBER, 30, 11, 0)), (timestamp(2017, SEPTEMBER, 30, 1, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, SEPTEMBER, 30, 12, 0)), (timestamp(2017, SEPTEMBER, 30, 2, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, SEPTEMBER, 30, 13, 0)), (timestamp(2017, SEPTEMBER, 30, 3, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, SEPTEMBER, 30, 22, 0)), (timestamp(2017, SEPTEMBER, 30, 12, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, SEPTEMBER, 30, 23, 0)), (timestamp(2017, SEPTEMBER, 30, 13, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 0, 0)), (timestamp(2017, SEPTEMBER, 30, 14, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 1, 0)), (timestamp(2017, SEPTEMBER, 30, 15, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 1, 59)), (timestamp(2017, SEPTEMBER, 30, 15, 59)));
|
||||
assertEquals(applyTimezone(unixTime(2017, JULY, 30, 18, 0)), (unixTime(2017, JULY, 30, 8, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, SEPTEMBER, 30, 0, 0)), (unixTime(2017, SEPTEMBER, 29, 14, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, SEPTEMBER, 30, 10, 0)), (unixTime(2017, SEPTEMBER, 30, 0, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, SEPTEMBER, 30, 11, 0)), (unixTime(2017, SEPTEMBER, 30, 1, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, SEPTEMBER, 30, 12, 0)), (unixTime(2017, SEPTEMBER, 30, 2, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, SEPTEMBER, 30, 13, 0)), (unixTime(2017, SEPTEMBER, 30, 3, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, SEPTEMBER, 30, 22, 0)), (unixTime(2017, SEPTEMBER, 30, 12, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, SEPTEMBER, 30, 23, 0)), (unixTime(2017, SEPTEMBER, 30, 13, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 0, 0)), (unixTime(2017, SEPTEMBER, 30, 14, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 1, 0)), (unixTime(2017, SEPTEMBER, 30, 15, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 1, 59)), (unixTime(2017, SEPTEMBER, 30, 15, 59)));
|
||||
// DST begins
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 3, 0)), (timestamp(2017, SEPTEMBER, 30, 16, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 4, 0)), (timestamp(2017, SEPTEMBER, 30, 17, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 5, 0)), (timestamp(2017, SEPTEMBER, 30, 18, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 11, 0)), (timestamp(2017, OCTOBER, 1, 0, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 12, 0)), (timestamp(2017, OCTOBER, 1, 1, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 13, 0)), (timestamp(2017, OCTOBER, 1, 2, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 14, 0)), (timestamp(2017, OCTOBER, 1, 3, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 15, 0)), (timestamp(2017, OCTOBER, 1, 4, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 1, 19, 0)), (timestamp(2017, OCTOBER, 1, 8, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, OCTOBER, 2, 19, 0)), (timestamp(2017, OCTOBER, 2, 8, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2017, NOVEMBER, 30, 19, 0)), (timestamp(2017, NOVEMBER, 30, 8, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, MARCH, 31, 0, 0)), (timestamp(2018, MARCH, 30, 13, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, MARCH, 31, 12, 0)), (timestamp(2018, MARCH, 31, 1, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, MARCH, 31, 18, 0)), (timestamp(2018, MARCH, 31, 7, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, APRIL, 1, 0, 0)), (timestamp(2018, MARCH, 31, 13, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, APRIL, 1, 1, 0)), (timestamp(2018, MARCH, 31, 14, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, APRIL, 1, 1, 59)), (timestamp(2018, MARCH, 31, 14, 59)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 3, 0)), (unixTime(2017, SEPTEMBER, 30, 16, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 4, 0)), (unixTime(2017, SEPTEMBER, 30, 17, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 5, 0)), (unixTime(2017, SEPTEMBER, 30, 18, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 11, 0)), (unixTime(2017, OCTOBER, 1, 0, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 12, 0)), (unixTime(2017, OCTOBER, 1, 1, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 13, 0)), (unixTime(2017, OCTOBER, 1, 2, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 14, 0)), (unixTime(2017, OCTOBER, 1, 3, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 15, 0)), (unixTime(2017, OCTOBER, 1, 4, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 1, 19, 0)), (unixTime(2017, OCTOBER, 1, 8, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, OCTOBER, 2, 19, 0)), (unixTime(2017, OCTOBER, 2, 8, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2017, NOVEMBER, 30, 19, 0)), (unixTime(2017, NOVEMBER, 30, 8, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, MARCH, 31, 0, 0)), (unixTime(2018, MARCH, 30, 13, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, MARCH, 31, 12, 0)), (unixTime(2018, MARCH, 31, 1, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, MARCH, 31, 18, 0)), (unixTime(2018, MARCH, 31, 7, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, APRIL, 1, 0, 0)), (unixTime(2018, MARCH, 31, 13, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, APRIL, 1, 1, 0)), (unixTime(2018, MARCH, 31, 14, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, APRIL, 1, 1, 59)), (unixTime(2018, MARCH, 31, 14, 59)));
|
||||
// DST ends
|
||||
assertEquals(applyTimezone(timestamp(2018, APRIL, 1, 2, 0)), (timestamp(2018, MARCH, 31, 16, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, APRIL, 1, 3, 0)), (timestamp(2018, MARCH, 31, 17, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, APRIL, 1, 4, 0)), (timestamp(2018, MARCH, 31, 18, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, APRIL, 1, 10, 0)), (timestamp(2018, APRIL, 1, 0, 0)));
|
||||
assertEquals(applyTimezone(timestamp(2018, APRIL, 1, 18, 0)), (timestamp(2018, APRIL, 1, 8, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, APRIL, 1, 2, 0)), (unixTime(2018, MARCH, 31, 16, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, APRIL, 1, 3, 0)), (unixTime(2018, MARCH, 31, 17, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, APRIL, 1, 4, 0)), (unixTime(2018, MARCH, 31, 18, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, APRIL, 1, 10, 0)), (unixTime(2018, APRIL, 1, 0, 0)));
|
||||
assertEquals(applyTimezone(unixTime(2018, APRIL, 1, 18, 0)), (unixTime(2018, APRIL, 1, 8, 0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_removeTimezone()
|
||||
{
|
||||
DateUtils.setFixedTimeZone(TimeZone.getTimeZone("Australia/Sydney"));
|
||||
assertEquals(removeTimezone(timestamp(2017, JULY, 30, 8, 0)), (timestamp(2017, JULY, 30, 18, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 29, 14, 0)), (timestamp(2017, SEPTEMBER, 30, 0, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 0, 0)), (timestamp(2017, SEPTEMBER, 30, 10, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 1, 0)), (timestamp(2017, SEPTEMBER, 30, 11, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 2, 0)), (timestamp(2017, SEPTEMBER, 30, 12, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 3, 0)), (timestamp(2017, SEPTEMBER, 30, 13, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 12, 0)), (timestamp(2017, SEPTEMBER, 30, 22, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 13, 0)), (timestamp(2017, SEPTEMBER, 30, 23, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 14, 0)), (timestamp(2017, OCTOBER, 1, 0, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 15, 0)), (timestamp(2017, OCTOBER, 1, 1, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 15, 59)), (timestamp(2017, OCTOBER, 1, 1, 59)));
|
||||
assertEquals(removeTimezone(unixTime(2017, JULY, 30, 8, 0)), (unixTime(2017, JULY, 30, 18, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 29, 14, 0)), (unixTime(2017, SEPTEMBER, 30, 0, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 0, 0)), (unixTime(2017, SEPTEMBER, 30, 10, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 1, 0)), (unixTime(2017, SEPTEMBER, 30, 11, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 2, 0)), (unixTime(2017, SEPTEMBER, 30, 12, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 3, 0)), (unixTime(2017, SEPTEMBER, 30, 13, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 12, 0)), (unixTime(2017, SEPTEMBER, 30, 22, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 13, 0)), (unixTime(2017, SEPTEMBER, 30, 23, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 14, 0)), (unixTime(2017, OCTOBER, 1, 0, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 15, 0)), (unixTime(2017, OCTOBER, 1, 1, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 15, 59)), (unixTime(2017, OCTOBER, 1, 1, 59)));
|
||||
// DST begins
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 16, 0)), (timestamp(2017, OCTOBER, 1, 3, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 17, 0)), (timestamp(2017, OCTOBER, 1, 4, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, SEPTEMBER, 30, 18, 0)), (timestamp(2017, OCTOBER, 1, 5, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, OCTOBER, 1, 0, 0)), (timestamp(2017, OCTOBER, 1, 11, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, OCTOBER, 1, 1, 0)), (timestamp(2017, OCTOBER, 1, 12, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, OCTOBER, 1, 2, 0)), (timestamp(2017, OCTOBER, 1, 13, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, OCTOBER, 1, 3, 0)), (timestamp(2017, OCTOBER, 1, 14, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, OCTOBER, 1, 4, 0)), (timestamp(2017, OCTOBER, 1, 15, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, OCTOBER, 1, 8, 0)), (timestamp(2017, OCTOBER, 1, 19, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, OCTOBER, 2, 8, 0)), (timestamp(2017, OCTOBER, 2, 19, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2017, NOVEMBER, 30, 8, 0)), (timestamp(2017, NOVEMBER, 30, 19, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, MARCH, 30, 13, 0)), (timestamp(2018, MARCH, 31, 0, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, MARCH, 31, 1, 0)), (timestamp(2018, MARCH, 31, 12, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, MARCH, 31, 7, 0)), (timestamp(2018, MARCH, 31, 18, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, MARCH, 31, 13, 0)), (timestamp(2018, APRIL, 1, 0, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, MARCH, 31, 14, 0)), (timestamp(2018, APRIL, 1, 1, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, MARCH, 31, 14, 59)), (timestamp(2018, APRIL, 1, 1, 59)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 16, 0)), (unixTime(2017, OCTOBER, 1, 3, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 17, 0)), (unixTime(2017, OCTOBER, 1, 4, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, SEPTEMBER, 30, 18, 0)), (unixTime(2017, OCTOBER, 1, 5, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, OCTOBER, 1, 0, 0)), (unixTime(2017, OCTOBER, 1, 11, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, OCTOBER, 1, 1, 0)), (unixTime(2017, OCTOBER, 1, 12, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, OCTOBER, 1, 2, 0)), (unixTime(2017, OCTOBER, 1, 13, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, OCTOBER, 1, 3, 0)), (unixTime(2017, OCTOBER, 1, 14, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, OCTOBER, 1, 4, 0)), (unixTime(2017, OCTOBER, 1, 15, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, OCTOBER, 1, 8, 0)), (unixTime(2017, OCTOBER, 1, 19, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, OCTOBER, 2, 8, 0)), (unixTime(2017, OCTOBER, 2, 19, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2017, NOVEMBER, 30, 8, 0)), (unixTime(2017, NOVEMBER, 30, 19, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, MARCH, 30, 13, 0)), (unixTime(2018, MARCH, 31, 0, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, MARCH, 31, 1, 0)), (unixTime(2018, MARCH, 31, 12, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, MARCH, 31, 7, 0)), (unixTime(2018, MARCH, 31, 18, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, MARCH, 31, 13, 0)), (unixTime(2018, APRIL, 1, 0, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, MARCH, 31, 14, 0)), (unixTime(2018, APRIL, 1, 1, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, MARCH, 31, 14, 59)), (unixTime(2018, APRIL, 1, 1, 59)));
|
||||
// DST ends
|
||||
assertEquals(removeTimezone(timestamp(2018, MARCH, 31, 16, 0)), (timestamp(2018, APRIL, 1, 2, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, MARCH, 31, 17, 0)), (timestamp(2018, APRIL, 1, 3, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, MARCH, 31, 18, 0)), (timestamp(2018, APRIL, 1, 4, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, APRIL, 1, 0, 0)), (timestamp(2018, APRIL, 1, 10, 0)));
|
||||
assertEquals(removeTimezone(timestamp(2018, APRIL, 1, 8, 0)), (timestamp(2018, APRIL, 1, 18, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, MARCH, 31, 16, 0)), (unixTime(2018, APRIL, 1, 2, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, MARCH, 31, 17, 0)), (unixTime(2018, APRIL, 1, 3, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, MARCH, 31, 18, 0)), (unixTime(2018, APRIL, 1, 4, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, APRIL, 1, 0, 0)), (unixTime(2018, APRIL, 1, 10, 0)));
|
||||
assertEquals(removeTimezone(unixTime(2018, APRIL, 1, 8, 0)), (unixTime(2018, APRIL, 1, 18, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user