String slicing not functioning in go-jira templates

I’m having trouble with go-jira templates. I want to extract the date part from a timestamp but it’s not working as expected. Here’s what I’m trying:

[Issue:{{- .key -}}:{{ .fields.resolution.name }}] begins {{ slice .fields.created 0 10 }} and finishes {{ slice .fields.resolutiondate 0 10 }}

But I get this error:

Invalid Usage: template: gojira:7:62: executing "gojira" at <slice .fields.created 0 10>: error calling slice: list should be type of slice or array but string

The docs say slice should work with strings too. Am I doing something wrong? My full template is a Gantt chart setup with ticket info and dates. Any help would be great!

I’ve actually been working extensively with go-jira templates recently, and I can offer some insights. While the slice function can be finicky, I’ve found a workaround that’s been reliable for me. Instead of using slice or substr, I’ve had success with the ‘now’ function combined with date formatting. Here’s what worked for me:

{{ .fields.created | date “2006-01-02” }}

This approach not only extracts the date portion but also ensures consistency across different timestamp formats. It’s been a game-changer for my Gantt chart implementations.

One thing to watch out for: make sure your .fields.resolutiondate isn’t null, as that can throw a wrench in the works. You might want to add a conditional check to handle unresolved issues gracefully.

Hope this helps with your template. Let me know if you need any clarification on implementation!

I encountered a similar issue when working with go-jira templates. The slice function can indeed be problematic for string operations. A more reliable approach is to use the date formatting capabilities of go-jira. Try this instead:

{{ .fields.created | date “2006-01-02” }}

This format string extracts just the date portion from the timestamp. It’s more robust and less likely to break if the timestamp format changes. For the resolution date, you can use the same approach:

{{ .fields.resolutiondate | date “2006-01-02” }}

This method should work consistently for your Gantt chart setup, providing clean date outputs without relying on string slicing.

hey charlieLion, i ran into this issue too. The slice function in go-jira templates is tricky. Have you tried using the substr function instead? It worked for me:

{{ substr .fields.created 0 10 }}

might solve ur problem. Good luck with the gantt chart setup!