Skip to content

Issue 151220/add current timezone offset variable#170518

Merged
jrieken merged 4 commits intomicrosoft:mainfrom
MonadChains:issue-151220/add-CURRENT-TIMEZONE-OFFSET-VARIABLE
Apr 24, 2023
Merged

Issue 151220/add current timezone offset variable#170518
jrieken merged 4 commits intomicrosoft:mainfrom
MonadChains:issue-151220/add-CURRENT-TIMEZONE-OFFSET-VARIABLE

Conversation

@MonadChains
Copy link
Contributor

Solves #151220

@mattjohnsonpint
Copy link

Please also add tests, or update these ones. Thanks.

test('Add time variables for snippets #41631, #43140', function () {
const resolver = new TimeBasedVariableResolver;
assertVariableResolve3(resolver, 'CURRENT_YEAR');
assertVariableResolve3(resolver, 'CURRENT_YEAR_SHORT');
assertVariableResolve3(resolver, 'CURRENT_MONTH');
assertVariableResolve3(resolver, 'CURRENT_DATE');
assertVariableResolve3(resolver, 'CURRENT_HOUR');
assertVariableResolve3(resolver, 'CURRENT_MINUTE');
assertVariableResolve3(resolver, 'CURRENT_SECOND');
assertVariableResolve3(resolver, 'CURRENT_DAY_NAME');
assertVariableResolve3(resolver, 'CURRENT_DAY_NAME_SHORT');
assertVariableResolve3(resolver, 'CURRENT_MONTH_NAME');
assertVariableResolve3(resolver, 'CURRENT_MONTH_NAME_SHORT');
assertVariableResolve3(resolver, 'CURRENT_SECONDS_UNIX');
});
test('Time-based snippet variables resolve to the same values even as time progresses', async function () {
const snippetText = `
$CURRENT_YEAR
$CURRENT_YEAR_SHORT
$CURRENT_MONTH
$CURRENT_DATE
$CURRENT_HOUR
$CURRENT_MINUTE
$CURRENT_SECOND
$CURRENT_DAY_NAME
$CURRENT_DAY_NAME_SHORT
$CURRENT_MONTH_NAME
$CURRENT_MONTH_NAME_SHORT
$CURRENT_SECONDS_UNIX
`;
const clock = sinon.useFakeTimers();
try {
const resolver = new TimeBasedVariableResolver;
const firstResolve = new SnippetParser().parse(snippetText).resolveVariables(resolver);
clock.tick((365 * 24 * 3600 * 1000) + (24 * 3600 * 1000) + (3661 * 1000)); // 1 year + 1 day + 1 hour + 1 minute + 1 second
const secondResolve = new SnippetParser().parse(snippetText).resolveVariables(resolver);
assert.strictEqual(firstResolve.toString(), secondResolve.toString(), `Time-based snippet variables resolved differently`);
} finally {
clock.restore();
}
});

@MonadChains MonadChains dismissed a stale review via 80ac0f3 January 3, 2023 23:15
@MonadChains
Copy link
Contributor Author

@mattjohnsonpint I've add the new variable to the tests

@mattjohnsonpint
Copy link

LGTM, but I'm not a maintainer of this repo.

@redactedscribe
Copy link

@jrieken Any chance we could get this PR approved? Would love to see this in VS Code.

@jrieken
Copy link
Member

jrieken commented Apr 24, 2023

Yeah, this slipped my inbox.

@jrieken jrieken added this to the April 2023 milestone Apr 24, 2023
@jrieken jrieken merged commit 0a6b7a3 into microsoft:main Apr 24, 2023
@redactedscribe
Copy link

Just FYI, this new variable isn't documented on https://code.visualstudio.com/docs/editor/userdefinedsnippets

@github-actions github-actions bot locked and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants