Skip to content

Commit 64ec5c5

Browse files
alexwoodgateAlex Woodgate
andauthored
Add upper/lower presentation format for am/pm in fromMillis (#277)
Signed-off-by: Alex Woodgate <alwoodga@uk.ibm.com> Co-authored-by: Alex Woodgate <alwoodga@uk.ibm.com>
1 parent 966b539 commit 64ec5c5

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/java/com/api/jsonata4java/expressions/utils/DateTimeUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,13 @@ private static String formatComponent(LocalDateTime date, SpecPart markerSpec, i
774774
if (offset == 0 && markerSpec.presentation2 != null && markerSpec.presentation2 == 't') {
775775
componentValue = "Z";
776776
}
777+
} else if (markerSpec.component == 'P') {
778+
// §9.8.4.7 Formatting Other Components
779+
// Formatting P for am/pm
780+
// getDateTimeFragment() always returns am/pm lower case so check for UPPER here
781+
if (markerSpec.names == tcase.UPPER) {
782+
componentValue = componentValue.toUpperCase();
783+
}
777784
}
778785
return componentValue;
779786
}

src/test/java/com/api/jsonata4java/expressions/FromMillisFunctionTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ public static Collection<Object[]> data() {
296296
// { "$fromMillis(1483272000000, \"Week: [w] of [xNn]\")","\"Week: 5 of December\"",null},
297297
// { "$fromMillis(1533038400000, \"Week: [w] of [xNn]\")","\"Week: 1 of August\"",null},
298298
// { "$fromMillis(1419940800000, \"Week: [w] of [xNn]\")","\"Week: 1 of January\"",null},
299+
{
300+
"$fromMillis(1521801216617, \"[F], [D]/[M]/[Y] [h]:[m]:[s] [PN]\")", "\"friday, 23/3/2018 10:33:36 AM\"", null
301+
},
302+
{
303+
"$fromMillis(1521801216617, \"[F], [D]/[M]/[Y] [h]:[m]:[s] [Pn]\")", "\"friday, 23/3/2018 10:33:36 am\"", null
304+
},
299305
});
300306
}
301307

0 commit comments

Comments
 (0)