Repository: jsonata-js/jsonata
Pull request #642 (2023-07-22 13:49:27)

Update construction.md
Simple consistency fix


Patch:
diff --git a/docs/construction.md b/docs/construction.md
index 4705ee5..81a42d5 100644
--- a/docs/construction.md
+++ b/docs/construction.md
@@ -44,7 +44,7 @@ __Examples__
 
 ## Object constructors
 
-In a similar manner to the way arrays can be constructed, JSON objects can also be constructed in the output.  At any point in a location path where a field reference is expected, a pair of braces `{}` containing key/value pairs separated by commas, with each key and value separated by a colon: `{key1: value2, key2:value2}`.  The keys and values can either be literals or can be expressions. The key must either be a string or an expression that evaluates to a string.
+In a similar manner to the way arrays can be constructed, JSON objects can also be constructed in the output.  At any point in a location path where a field reference is expected, a pair of braces `{}` containing key/value pairs separated by commas, with each key and value separated by a colon: `{key1: value1, key2:value2}`.  The keys and values can either be literals or can be expressions. The key must either be a string or an expression that evaluates to a string.
 
 When an object constructor follows an expression that selects multiple values, the object constructor will create a single object that contains a key/value pair for each of those context values.  If an array of objects is required (one for each context value), then the object constructor should immediately follow the dot '.' operator.
 
diff --git a/src/datetime.js b/src/datetime.js
index 00d80ea..0121765 100644
--- a/src/datetime.js
+++ b/src/datetime.js
@@ -904,6 +904,13 @@ const dateTime = (function () {
                 if (offset === 0 && markerSpec.presentation2 === 't') {
                     componentValue = 'Z';
                 }
+            } else if (markerSpec.component === 'P') {
+                // §9.8.4.7 Formatting Other Components
+                // Formatting P for am/pm
+                // getDateTimeFragment() always returns am/pm lower case so check for UPPER here
+                if (markerSpec.names === tcase.UPPER) {
+                    componentValue = componentValue.toUpperCase();
+                }
             }
             return componentValue;
         };


Test patch:
diff --git a/test/test-suite/groups/function-fromMillis/formatDateTime.json b/test/test-suite/groups/function-fromMillis/formatDateTime.json
index 96e1962..c08a9ea 100644
--- a/test/test-suite/groups/function-fromMillis/formatDateTime.json
+++ b/test/test-suite/groups/function-fromMillis/formatDateTime.json
@@ -539,6 +539,22 @@
             "2018-10-21T13:05:00.000Z"
         ]
     },
+    {
+        "function": "#fromMillis",
+        "category": "Upper case AM/PM presentation",
+        "description": "am/pm presentation should be set to uppercase AM",
+        "expr": "$fromMillis(1521801216617, '[F], [D]/[M]/[Y] [h]:[m]:[s] [PN]')",
+        "data": {},
+        "result": "friday, 23/3/2018 10:33:36 AM"
+    },
+    {
+        "function": "#fromMillis",
+        "category": "Lower case AM/PM presentation",
+        "description": "am/pm presentation should be set to lowercase am",
+        "expr": "$fromMillis(1521801216617, '[F], [D]/[M]/[Y] [h]:[m]:[s] [Pn]')",
+        "data": {},
+        "result": "friday, 23/3/2018 10:33:36 am"
+    },
     {
         "function": "#fromMillis",
         "category": "error",