{"ScriptPreparationCode":"function parseDateAsUtc(dateString) {\r\n // Check if the string already has a timezone indicator (Z or \u002B/-HH:mm)\r\n const hasTimezoneIndicator = /[\u002B-]\\d{2}:\\d{2}$|Z$/i.test(dateString);\r\n\r\n let fullIsoString = dateString;\r\n\r\n if (!hasTimezoneIndicator) {\r\n // If no timezone, we need to add \u0027Z\u0027 to ensure it\u0027s parsed as UTC.\r\n // We also need to fill in missing time components to make it a valid ISO string.\r\n // Example: \u00272025-07-18\u0027 -\u003E \u00272025-07-18T00:00:00Z\u0027\r\n // \u00272025-07-18T18\u0027 -\u003E \u00272025-07-18T18:00:00Z\u0027\r\n // \u00272025-07-18T18:30\u0027 -\u003E \u00272025-07-18T18:30:00Z\u0027\r\n // \u00272025-07-18T18:45:05\u0027 -\u003E \u00272025-07-18T18:45:05Z\u0027\r\n\r\n if (!dateString.includes(\u0027T\u0027)) { // If only date part, add T00:00:00Z\r\n fullIsoString \u002B= \u0027T00:00:00Z\u0027;\r\n } else { // Has time part, but might be incomplete\r\n const [datePart, timePart] = dateString.split(\u0027T\u0027);\r\n const parts = timePart.split(\u0027:\u0027);\r\n\r\n let hours = parts[0] || \u002700\u0027;\r\n let minutes = parts[1] || \u002700\u0027;\r\n let seconds = parts[2] || \u002700\u0027;\r\n\r\n fullIsoString = \u0060${datePart}T${hours}:${minutes}:${seconds}Z\u0060;\r\n }\r\n }\r\n\r\n // Use the native Date constructor, which is robust at parsing full ISO strings.\r\n // It will correctly interpret a string ending in \u0027Z\u0027 as UTC.\r\n return new Date(fullIsoString);\r\n}","TestCases":[{"Name":"MomentJS","Code":"const cacheDurationMinutes = 60;\r\nconst defaultTtl = cacheDurationMinutes * 60;\r\nconst effectiveDate = \u00272025-07-18T18\u0027;\r\nconst now = moment.utc();\r\nconst keyEffectiveDateStart = moment.utc(effectiveDate);\r\nconst keyEffectiveDateEnd = keyEffectiveDateStart.clone()\r\n.add(cacheDurationMinutes, \u0027minutes\u0027);\r\nconst secondsTillKeyEnd = keyEffectiveDateEnd.diff(now, \u0027seconds\u0027);\r\n\r\nconst result = Math.min(defaultTtl, Math.max(0, secondsTillKeyEnd)) || defaultTtl;","IsDeferred":false},{"Name":"Date JS","Code":"const cacheDurationMinutes = 60;\r\nconst defaultTtl = cacheDurationMinutes * 60;\r\n\r\nconst effectiveDate = \u00272025-07-18T18\u0027; \r\n\r\nconst now = new Date();\r\n\r\nconst keyEffectiveDateStart = parseDateAsUtc(effectiveDate);\r\n\r\nconst keyEffectiveDateEnd = new Date(keyEffectiveDateStart.getTime()); \r\n\r\nkeyEffectiveDateEnd.setUTCMinutes(keyEffectiveDateEnd.getUTCMinutes() \u002B cacheDurationMinutes); \r\n\r\nconst secondsTillKeyEnd = (keyEffectiveDateEnd.getTime() - now.getTime()) / 1000;\r\n\r\nconst result = Math.min(defaultTtl, Math.max(0, secondsTillKeyEnd)) || defaultTtl; ","IsDeferred":false},{"Name":"Date-Fns","Code":"const cacheDurationMinutes = 60;\r\nconst defaultTtl = cacheDurationMinutes * 60;\r\n\r\nconst effectiveDate = \u00272025-07-18T18\u0027;\r\n\r\nconst now = new Date();\r\n\r\nconst keyEffectiveDateStart = parseDateAsUtc(effectiveDate);\r\n\r\nconst keyEffectiveDateEnd = dateFns.addMinutes(keyEffectiveDateStart, cacheDurationMinutes);\r\n\r\nconst secondsTillKeyEnd = dateFns.differenceInSeconds(keyEffectiveDateEnd, now);\r\n\r\nconst result = Math.min(defaultTtl, Math.max(0, secondsTillKeyEnd)) || defaultTtl;","IsDeferred":false}]}