forked from plusonelabs/calendar-widget
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
27 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
app/src/androidTest/java/org/andstatus/todoagenda/prefs/DateFormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.andstatus.todoagenda.prefs; | ||
|
||
import org.andstatus.todoagenda.BaseWidgetTest; | ||
import org.andstatus.todoagenda.prefs.dateformat.DateFormatType; | ||
import org.andstatus.todoagenda.prefs.dateformat.DateFormatValue; | ||
import org.andstatus.todoagenda.prefs.dateformat.DateFormatter; | ||
import org.joda.time.DateTime; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
public class DateFormatterTest extends BaseWidgetTest { | ||
|
||
@Test | ||
public void timeTimeZones() { | ||
InstanceSettings settings = getSettings(); | ||
settings.clock().setSnapshotMode(SnapshotMode.SNAPSHOT_TIME); | ||
assertNow("2020-02-15T01:00:00.000+08:00"); | ||
assertNow("2020-02-15T23:00:00.000+08:00"); | ||
assertNow("2020-02-29T01:00:00.000+08:00"); | ||
assertNow("2020-02-29T23:00:00.000+08:00"); | ||
assertNow("2020-02-15T01:00:00.000-05:00"); | ||
assertNow("2020-02-15T23:00:00.000-05:00"); | ||
assertNow("2020-02-29T01:00:00.000-05:00"); | ||
assertNow("2020-02-29T23:00:00.000-05:00"); | ||
assertNow("2025-03-01T23:00:00.000-01:00"); | ||
} | ||
|
||
private void assertNow(String pattern) { | ||
DateTime now = DateTime.parse(pattern); | ||
getSettings().clock().setSnapshotDate(now); | ||
|
||
assertPattern(now, "MM-dd b", String.format("%02d-%02d", now.monthOfYear().get(), | ||
now.dayOfMonth().get()) + " 0"); | ||
|
||
DateTime yesterday = now.minusDays(1); | ||
assertPattern(yesterday, "MM-dd b", String.format("%02d-%02d", yesterday.monthOfYear().get(), | ||
yesterday.dayOfMonth().get()) + " -1"); | ||
assertPattern(yesterday, "b MM.dd", "-1 " + String.format("%02d.%02d", yesterday.monthOfYear().get(), | ||
yesterday.dayOfMonth().get())); | ||
assertPattern(yesterday, "MM.b.dd", String.format("%02d.-1.%02d", yesterday.monthOfYear().get(), | ||
yesterday.dayOfMonth().get())); | ||
|
||
DateTime tomorrow = now.plusDays(1); | ||
assertPattern(tomorrow, "MM-dd b", String.format("%02d-%02d", tomorrow.monthOfYear().get(), | ||
tomorrow.dayOfMonth().get()) + " 1"); | ||
} | ||
|
||
@Test | ||
public void customPatterns() { | ||
InstanceSettings settings = getSettings(); | ||
settings.clock().setSnapshotMode(SnapshotMode.SNAPSHOT_TIME); | ||
DateTime now = settings.clock().now().withTimeAtStartOfDay().plusHours(1); | ||
settings.clock().setSnapshotDate(now); | ||
|
||
assertPattern(now, "yyyy-MM-dd b", String.format("%04d-%02d-%02d", now.yearOfEra().get(), | ||
now.monthOfYear().get(), now.dayOfMonth().get()) + " 0"); | ||
assertPattern(now, "b", "0"); | ||
assertPattern(now, "MM-dd bb", String.format("%02d-%02d", now.monthOfYear().get(), now.dayOfMonth().get()) + " 00"); | ||
assertPattern(now.plusDays(1), "", ""); | ||
assertPattern(now.plusDays(1), "b", "1"); | ||
assertPattern(now.plusDays(1), "'begin' b", "begin 1"); | ||
} | ||
|
||
private void assertPattern(DateTime date, String pattern, String expected) { | ||
DateFormatValue format = DateFormatValue.of(DateFormatType.CUSTOM, pattern); | ||
DateTime now = getSettings().clock().now(); | ||
DateFormatter formatter = new DateFormatter(getSettings().getContext(), format, now); | ||
assertEquals("Date: " + date + ", Now:" + now + ", Pattern: [" + pattern + "]", expected, formatter.formatDate(date)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters