Skip to content

Commit

Permalink
Merge pull request #597 from dimagi/nh/day-of-week
Browse files Browse the repository at this point in the history
Support for "%w" date format for day of week
  • Loading branch information
ctsims authored Jun 26, 2017
2 parents 66724f8 + 885fe06 commit 7cba244
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/org/javarosa/core/model/utils/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ public static String format(DateFields f, String format) {
} else if (c == 'a') { //Three letter short text day
String[] dayNames = new String[]{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
sb.append(dayNames[f.dow - 1]);
} else if (Arrays.asList('c', 'C', 'D', 'F', 'g', 'G', 'I', 'j', 'k', 'l', 'p', 'P', 'r', 'R', 's', 't', 'T', 'u', 'U', 'V', 'w', 'W', 'x', 'X', 'z', 'Z').contains(c)) {
} else if (c == 'w') { //Day of the week (0 through 6), Sunday being 0.
sb.append(f.dow - 1);
} else if (Arrays.asList('c', 'C', 'D', 'F', 'g', 'G', 'I', 'j', 'k', 'l', 'p', 'P', 'r', 'R', 's', 't', 'T', 'u', 'U', 'V', 'W', 'x', 'X', 'z', 'Z').contains(c)) {
// Format specifiers supported by libc's strftime: https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html
throw new RuntimeException("unsupported escape in date format string [%" + c + "]");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public void testFormat() {
escapesResults.put("%B", "November");
escapesResults.put("%d", "05");
escapesResults.put("%e", "5");
escapesResults.put("%w", "6");

for (String escape : escapesResults.keySet()) {
String result = escapesResults.get(escape);
Expand Down

0 comments on commit 7cba244

Please sign in to comment.