Skip to content

Timezone Support #7887

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

Open
wants to merge 3 commits into
base: dev/feature
Choose a base branch
from

Conversation

erenkarakal
Copy link
Member

@erenkarakal erenkarakal commented May 22, 2025

Problem

There isn't a way to get the date in a timezone without knowing its time offset.

Solution

Adds a new pattern to the now expression that lets you get the current clock time in the specified timezone. It won't be equal to now as it returns the shifted time (which will be mentioned in the syntax descriptions later).
Also adds a new expression for getting a list of valid time zones.

Syntaxes:
now [timezone:in time[ ]zone %-string%]
all time[ ]zones

Testing Completed

Only manual testing was done. Proper tests will be written after syntax/functionality reviews.

Supporting Information

  • - Tests
  • - Change description
  • - Add docs

Completes: none
Related: none

@erenkarakal erenkarakal requested a review from a team as a code owner May 22, 2025 15:47
@erenkarakal erenkarakal requested review from Efnilite and cheeezburga and removed request for a team May 22, 2025 15:47
@skriptlang-automation skriptlang-automation bot added the needs reviews A PR that needs additional reviews label May 22, 2025
@sovdeeth sovdeeth added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label May 22, 2025
if (usingTimezone) {
String timezone = this.timezone.getSingle(event);
if (timezone == null) {
return new Date[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably throw a runtime error here

try {
targetZoneId = ZoneId.of(timezone);
} catch (DateTimeException e) { // invalid zone format
return new Date[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtime error

Copy link
Member Author

@erenkarakal erenkarakal May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about throwing an error here, there is no way to check if the timezone is valid
So the user can't sanitize it even if they wanted to

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add a condition to check if the timezone is a valid one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is a lookup on 603 time zones worth it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the user wants to yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something. needs reviews A PR that needs additional reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants