From f502032c4da529a8401c45f4b86de7de0bdc34f8 Mon Sep 17 00:00:00 2001 From: Meghan Eskolin Date: Thu, 14 Apr 2022 14:18:31 -0500 Subject: [PATCH] Support for parsing ISO 8601 duration format with only time component --- src/primitiveLiteral.ts | 2 +- test/primitive-cases.json | 80 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/primitiveLiteral.ts b/src/primitiveLiteral.ts index 627f5f1..213f015 100644 --- a/src/primitiveLiteral.ts +++ b/src/primitiveLiteral.ts @@ -187,7 +187,7 @@ export namespace PrimitiveLiteral { index++; let dayNext = Utils.required(value, index, Lexer.DIGIT, 1); if (dayNext === index && value[index + 1] !== 0x54) return; - index = dayNext; + if (dayNext != 0) index = dayNext; if (value[index] === 0x44) index++; let end = index; if (value[index] === 0x54) { diff --git a/test/primitive-cases.json b/test/primitive-cases.json index d0625a3..a01fe55 100644 --- a/test/primitive-cases.json +++ b/test/primitive-cases.json @@ -325,6 +325,86 @@ "value": "Edm.Duration" } }, + { + "-Name": "Duration 0 days", + "-Rule": "duration", + "Input": "duration'P0D'", + "result": { + "position": 0, + "type": "Literal", + "value": "Edm.Duration" + } + }, + { + "-Name": "Duration 2-digit days", + "-Rule": "duration", + "Input": "duration'P10D'", + "result": { + "position": 0, + "type": "Literal", + "value": "Edm.Duration" + } + }, + { + "-Name": "Duration days and hours", + "-Rule": "duration", + "Input": "duration'P10DT23H'", + "result": { + "position": 0, + "type": "Literal", + "value": "Edm.Duration" + } + }, + { + "-Name": "Duration 0 days and 2 hours", + "-Rule": "duration", + "Input": "duration'P0DT2H'", + "result": { + "position": 0, + "type": "Literal", + "value": "Edm.Duration" + } + }, + { + "-Name": "Duration hours no day component", + "-Rule": "duration", + "Input": "duration'PT2H'", + "result": { + "position": 0, + "type": "Literal", + "value": "Edm.Duration" + } + }, + { + "-Name": "Duration minutes no day component", + "-Rule": "duration", + "Input": "duration'PT30M'", + "result": { + "position": 0, + "type": "Literal", + "value": "Edm.Duration" + } + }, + { + "-Name": "Duration seconds no day component", + "-Rule": "duration", + "Input": "duration'PT5S'", + "result": { + "position": 0, + "type": "Literal", + "value": "Edm.Duration" + } + }, + { + "-Name": "Duration seconds missing T", + "-Rule": "duration", + "Input": "duration'P5S'", + "result_error": { + "position": 0, + "type": "Literal", + "value": "Edm.Duration" + } + }, { "-Name": "Decimal: integer", "-Rule": "decimalValue",