Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot format date #225

Open
bsinou opened this issue Aug 31, 2023 · 10 comments
Open

Cannot format date #225

bsinou opened this issue Aug 31, 2023 · 10 comments
Assignees
Labels

Comments

@bsinou
Copy link

bsinou commented Aug 31, 2023

Hi,

First, thanks for the great job, it helps a lot! I yet have an issue while handling dates.

Expected Behavior

Start and End (retrieved with currentDate) timestamps should be displayed using iso format.

Current Behavior

Date are generated in the form of 8/31/23, 9:00 AM, both in previews and in the payload that is sent to the webhook.

Steps to Reproduce (for bugs)

  1. Define a new template with
    • Date Format: yyyy-MM-ddTHH:mm:ssZ
    • Payload Format: jsonVelocityTemplate
  2. Get the date in the json with eg:
{
        "TimeStarted": "${buildStartTime}", 
        "TimeEnd": "${currentTime}"
}
  1. Try both preview and webhook => dates are still wrongly formatted.

I have also tried to get access to the dateTool object [1] without success.

Your Environment

  • tcWebHooks Version: Initially tried with 1.2.2 (from the market place) and then also with 1.2.4 and 2.0.0-rc2 (directly from github)
  • TeamCity Version: 2023.05.3

Any hint would be greatly appreciated.

[1]: Seems like it has been added for 1.2.4 at least

@netwolfuk
Copy link
Member

Thanks for raising this bug. What you're doing should be working. I'll take a look when I get to a computer.

@netwolfuk
Copy link
Member

I can't see why setting the dateformat on the template is not working. I'll try to do some more investigation on the weekend.

I was able to use datetool (in version 1.2.4) with the following Velocity template...

{
        "startDate": "$dateTool.format('iso_tz', ${build.StartDate.Time})"
        "currentTime": "$dateTool.format('iso_tz', $dateTool)"
}

outputs...

{
        "startDate": "2023-08-07T22:57:38Z"
        "currentTime": "2023-09-01T10:23:28Z"
}

$dateTool appear to use some odd formatting style (not the normal one as you would expect).
See https://velocity.apache.org/tools/devel/apidocs/org/apache/velocity/tools/generic/DateTool.html

@netwolfuk
Copy link
Member

I'll also patch 2.0.0 with the dateTool so that is same as 1.2.4 and release a new 2.0 RC. Hopefully will get that out on the weekend too.

@netwolfuk
Copy link
Member

You may have already seen this issue all about dates: #222
With some more examples on using dateTool with the objects in the template.

@netwolfuk
Copy link
Member

netwolfuk commented Sep 1, 2023

I was able to get $dateTool to use SimpleDateFormat format by setting a variable and then referencing...

#set($myDate = $dateTool.format("yyyy-MM-dd'T'HH:mm:ssZ",$dateTool))
{
        "iso_tz": "$dateTool.format('iso_tz',$dateTool)",
        "myDate": "$myDate"
}

It doesn't use Z for zulu time, but prints the offset (+0000)

{   
        "iso_tz": "2023-09-01T10:58:12Z",   
        "myDate": "2023-09-01T10:58:12+0000" 
}

@netwolfuk
Copy link
Member

netwolfuk commented Sep 1, 2023

Or you can set the format....

#set($myDate = $dateTool.format("yyyy-MM-dd'T'HH:mm:ssZ",$dateTool))
#set($myFormat = "yyyy-MM-dd'T'HH:mm:ssZ")

{
        "iso_tz": "$dateTool.format('iso_tz',$dateTool)",
        "myDate": "$myDate",
        "myFormat": "$dateTool.format($myFormat,$dateTool)"
}
{
        "iso_tz": "2023-09-01T11:03:15Z",
        "myDate": "2023-09-01T11:03:15+0000",
        "myFormat": "2023-09-01T11:03:15+0000"
}

@bsinou
Copy link
Author

bsinou commented Sep 1, 2023

Thanks a lot for all these explanations and tips.

This indeed fixes my problem until the date format issue is solved.

"endDate": "$dateTool.format('iso_tz',$dateTool)",

For the record yet, I could not have it work with v2-rc2: I had to revert both pluging (webhook and REST) to the 1.2.4

@netwolfuk
Copy link
Member

Yeah, sorry about that. The date tool is very new and I haven't released an updated 2.0.0: with it included yet.

@bsinou
Copy link
Author

bsinou commented Sep 1, 2023

No need to be sorry :)
You already saved my day with all your explanations and your prompt answer! Thanks again.

@netwolfuk
Copy link
Member

netwolfuk commented Sep 17, 2023

Hmm. There are lots of interesting bug in this behaviour.

  1. Previewing or executing in the template editor fails to pass the templateId or the preferredDateTime. Therefore the code has no way to determine how to resolve the date format you want.
  2. Previewing or executing the webhook from the webhook edit dialog box, throws a GSON exception.
    Update: My JSON was missing some commas, so it was not well defined. Once that was fixed the webhook preview worked.
  3. Executing a webhook from a build event does work (I tested with pinned event).

Result: Preview/test from the template editor does not support preferredDateTime. This is a bug.

@netwolfuk netwolfuk self-assigned this Sep 18, 2023
@netwolfuk netwolfuk added the bug label Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants