4

I have a liquid template that includes a date field, which I am not using any filters on at all, but it's getting converted from 2020-04-11T22:02:11Z UTC to 4/11/2020 10:02:11 PM. Is this expected behavior of DotLiquid or Azure Logic Apps? How can I prevent it from doing this?

Joe Eng
  • 1,072
  • 2
  • 15
  • 30

2 Answers2

6

I met the same problem in the past, liquid will convert the date time from 2020-04-11T22:02:11Z to 4/11/2020 10:02:11 PM automatically even if it is a string. As a workaround, we can use date format to convert it to the original date time.

For example, I have a json as below:

{
    "datetime": "2020-04-11T22:02:11Z"
}

We can use the liquid map like this:

{
    "datetime":"{{content.datetime | Date: "yyyy-MM-ddTHH:mm:ssZ"}}"
}

After that, we can get the original date format as 2020-04-11T22:02:11Z.

Hope it helps~

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • Thanks, Hury. Are you using DotLiquid or Logic Apps or just plain liquid? – Joe Eng Jul 09 '20 at 18:11
  • @JoeyEng I test it in logic app with integration account (liquid map). – Hury Shen Jul 10 '20 at 01:20
  • 1
    K, because I tested with plain liquid and it wasn't auto converting the date format. I think this might be DotLiquid since that's what Logic Apps uses, but just a guess. – Joe Eng Jul 10 '20 at 15:39
  • [DotLiquid](https://github.com/dotliquid/dotliquid/wiki/DotLiquid-Syntax-Compatibility) uses the [standard Microsoft date time format strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#the-round-trip-o-o-format-specifier) as default so you can use the 'O' format string to output ISO 8601 compliant date-time properties. For example: `"dateTime": "{{content.dateTime | Date: 'O'}}"` – John Jan 26 '22 at 14:15
0

If you're running DotLiquid locally and using the Newtonsoft JSON deserializer then you can tell it not to parse date-time strings and to leave them as strings:

JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
    DateParseHandling = DateParseHandling.None
};

The Azure Logic Apps workflow engine seems to mirror this behaviour as my date-time strings aren't changed.

John
  • 1,043
  • 15
  • 20