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

Date functions limited to local timezone #18

Closed
wburningham opened this issue May 8, 2024 · 2 comments
Closed

Date functions limited to local timezone #18

wburningham opened this issue May 8, 2024 · 2 comments

Comments

@wburningham
Copy link

Context:

I'm using slim-sprig in as part of a go-task/task Taskfile. The end goal is to be able to parse a a git commit timestamp into a particular UTC format. I'm working with various versions of git so I can't rely on the commit timestamp formatting built into git. I also have a hard constraint on the final format being in UTC.

Problem:

From what I can tell all date formatting functions in the slim-sprig library (ie dateInZone) hard codes the local timezone. This means there is no way to run time.Time.Format using the UTC timezone.

Solution:

If my problem stated above is correct (I may be missing something in how to accomplish the desire goal so please let me know if I missed something), I'd like to propose a method to format a date in a given timezone (or just support UTC). This could be exposing the dateInZone function or a new dateInUTC or something else.

I'm happy to submit a PR, but I'd like to get feedback on the agreed upon problem and solution.

Thanks

@andreynering
Copy link
Member

Hi @wburningham,

I didn't understand why dateInZone does not work for you, as I did a quick test and it seems to be working as expected:

version: '3'

tasks:
  date:
    cmds:
      - 'echo {{now | date "2006-01-02T15:04:05Z07:00"}}'
      - 'echo {{dateInZone "2006-01-02T15:04:05Z07:00" (now) "UTC"}}'

Hopefully that helps you to do what you need.


We don't usually add new functions to this fork because they should be directed to upstream.

That said, I just took a look, and the upstream repo is abandoned, and there is an attempt to have a maintained fork. See:

I opened an issue on the Task repo to track a possible migration to it in the future:

Just a FYI in case you find out another function is really needed. In that case, I think adding the function directly on the Task repo for now would possibly be the best option.

@wburningham
Copy link
Author

I was not using dateInZone correctly. We can close out the issue.

Thanks for sharing those links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants