vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Add TIMEZONE or TIMEZONE_OFFSET to User Defined Snippet Variables

Open SeaDude opened this issue 3 years ago • 5 comments
trafficstars

As outlined here and here, we still don't have the ability to script the creation of accurate, time-aware ISO8601 timestamps using VS Code. This is because we're missing a TIMEZONE element.

Please make this available.

Thank you

SeaDude avatar Jun 03 '22 14:06 SeaDude

FWIW, I agree with this request, and the name should probably be CURRENT_TZOFFSET. Its value should derive from Date.getTimezoneOffset and then be formatted accordingly, as seen as part of the larger string here.

I'd also suggest something like CURRENT_ISO8601_LOCAL_TIMESTAMP (built as shown in the prior link) and CURRENT_ISO8601_UTC_TIMESTAMP (which can be obtained directly from Date.toISOString)

Looks like the right place to add it would be here: https://github.com/microsoft/vscode/blob/71080eb345c19783eff945f2b047c6bf0803849a/src/vs/editor/contrib/snippet/browser/snippetVariables.ts#L259-L299

mattjohnsonpint avatar Jun 03 '22 18:06 mattjohnsonpint

This is very similar to #129030 in making snippets more international.

karlcow avatar Aug 21 '22 23:08 karlcow

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

vscodenpa avatar Aug 22 '22 07:08 vscodenpa

👍🏾

tianaranjo avatar Aug 24 '22 21:08 tianaranjo

Come on VS Code Community! Only 9 more upvotes to go and we can have complete timestamps in our SNIPPETS!

SeaDude avatar Sep 21 '22 19:09 SeaDude

4 to go!

ericthomas1 avatar Sep 22 '22 15:09 ericthomas1

2 upvotes to go!! Lets go VS Code Community!!

This enhancement will allow you to automatically create aware timestamps instead of having to manually manage your UTC relation info.

Example:

  • Here's what you have to do today to generate an aware timstamp:

    • ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}-07:00
    • If your locale recognizes daylight saving time, you have to manually adjust the UTC relation info (the -07:00 / 08:00)!
  • Here is what is proposed:

    • ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}${CURRENT_TZ}

Lets do this VS Code Community!

SeaDude avatar Sep 25 '22 16:09 SeaDude

:slightly_smiling_face: This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

vscodenpa avatar Sep 26 '22 03:09 vscodenpa

Nice work everyone!

SeaDude avatar Sep 26 '22 04:09 SeaDude

Awwww man! Daylight savings time and I forgot to go into my Snippets: Configure User Snippets markdown.json file and update all the -07's to -08's! All timestamps that I've created since DST ended over the weekend are incorrect.

It will be very nice when the ${CURRENT_TZ} built-in variable is available... :)

ericthomas1 avatar Nov 09 '22 22:11 ericthomas1

I've open a pull request that adds a CURRENT_TIMEZONE_OFFSET variable that display the offset as +/-hh:mm. Let me know if this solves your issue.

MonadChains avatar Jan 03 '23 21:01 MonadChains

Timezone changes are quickly approaching... seems the fix that @MonadChains proposed is blocked https://github.com/microsoft/vscode/pull/170518...

ericthomas1 avatar Mar 07 '23 21:03 ericthomas1

@MonadChains, thank you for addressing this request. I see the merge is blocked. Is there anything I can do to assist the ball forward?

ericthomas1 avatar Mar 13 '23 18:03 ericthomas1

https://github.com/microsoft/vscode/pull/170518 has been merged, this will ship with 1.78 stable and next/tomorrow's insiders

jrieken avatar Apr 24 '23 10:04 jrieken

@jrieken I'm not sure what the "verification-needed" label requires, but I can tell you that adding $CURRENT_TIMEZONE_OFFSET to a global snippet in today's Insider build works as expected, at least for my time zone which is a positive offset. The variable expands to format [+|-]##:##.


For an ISO 8601 date and time timestamp:

$CURRENT_YEAR-$CURRENT_MONTH-${CURRENT_DATE}T$CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND$CURRENT_TIMEZONE_OFFSET

Result:

2023-04-25T13:37:45+02:00

redactedscribe avatar Apr 25 '23 11:04 redactedscribe