mustache / spec

The Mustache spec.
MIT License
361 stars 71 forks source link

how to format date in mustache syntax with json template? #132

Closed abeerah1 closed 2 years ago

abeerah1 commented 3 years ago

{{date.now}} provides the exact format of the date/time I am looking to achieve, but I need to generate past date/times for more sample date. {{date.past}} is formatting the date completely written out rather than yyyy-mm-dd. how can I fix this? i'm using kinesis data generator to create a json template.

jgonggrijp commented 3 years ago

@abeerah1 date.now and date.past are just particular objects/properties/methods in your dataset, they are not part of the Mustache language. Perhaps take your question to the maintainers of the kinesis data generator.

Very generally speaking, if date is some kind of object with now and past as methods, then the return values of those methods will be interpolated into your template. The Mustache specification however has nothing to say about what those methods will return. It's up to you to pass data into your templates that behave in a way that you like.

abeerah1 commented 3 years ago

@jgonggrijp Here is my template so far:

[
{
    "Version": "2019-08-26",
    "AWSAccountId": "{{random.number(
        {
            "min": 123456789012345,
            "max": 23456789012345
}
)}}",

    "InstanceId": "7ed627be-486f-460d-816e-517153851070",
    "ContactId": {{random.number(
        {
            "min": 1234567890123456,
            "max": 234567890123456
}
)}},

    "CustomerName": "{{name.firstName}} {{name.lastName}}", 
    "Content": {{random.number(
        {
            "min": 1,
            "max": 4
}
)}},

    "AbsoluteTime": “{{date.past}}”

] 

I want the date to be randomly generated past date/time, but formatted like this: "2021-07-12T21:54:11.622Z"

is there anything I can add to what I have so far to accomplish this?

jgonggrijp commented 3 years ago

@abeerah1 I have no idea because I'm familiar with neither kinesis nor AWS. Your question doesn't seem to be directly related to the Mustache spec. I suggest you take your question to Stack Overflow, which is specifically meant for questions like these. See https://stackoverflow.com/help/how-to-ask for some tips on getting good help.

jgonggrijp commented 2 years ago

@spullara @Danappelxx I think this ticket can be closed.