Change:
Edit: Sorry if this is a terrible issue... The current list of variables available when writing a snippet can be found . Existing variables expose great contextual information - such as current file, directory, line number, word, etc. Development happens so fast that information can become outdated, so knowing when some custom snippets were inserted could be useful. For example, when creating files or adding comments. My current use case is a snippet that inserts copyright headers. The key binding inserts the header: It would help to include the date: and could also apply to updates or comments: Doing so could mean a simple variable like , but that may not work for non-US users who's date format is different i/e not month/day/year. Perhaps exposing the variables separately such as , etc or localization can help? I'd like to know if there is any interest in this. I know an extension could do this but it seems like overkill, but that could depend on potential use cases. Thanks for any feedback.
Hm, this is dupe of many requests we have gotten around this but made a valid point. Adding variables for year, month, day and hour, minute, second makes sense. That will allow anyone to compose it's own date. So, yeah feel free to drop a PR
Good to hear. Thanks for the PR!

Discussion:
import { IPosition } from 'vs/editor/common/core/position'; import { groupBy } from 'vs/base/common/arrays'; import { dispose } from 'vs/base/common/lifecycle'; <del> import { SelectionBasedVariableResolver, CompositeSnippetVariableResolver, ModelBasedVariableResolver, ClipboardBasedVariableResolver } from './snippetVariables'; </del> <ins> import { SelectionBasedVariableResolver, CompositeSnippetVariableResolver, ModelBasedVariableResolver, ClipboardBasedVariableResolver, TimeBasedVariableResolver } from './snippetVariables'; </ins> import { ModelDecorationOptions } from 'vs/editor/common/model/textModel'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';

.resolveVariables(new CompositeSnippetVariableResolver([ modelBasedVariableResolver, new ClipboardBasedVariableResolver(clipboardService, idx, indexedSelections.length), <del> new SelectionBasedVariableResolver(model, selection) </del> <ins> new SelectionBasedVariableResolver(model, selection), new TimeBasedVariableResolver </ins> ])); const offset = model.getOffsetAt(start) + delta;

import { ITextModel } from 'vs/editor/common/model'; import { Selection } from 'vs/editor/common/core/selection'; import { VariableResolver, Variable, Text } from 'vs/editor/contrib/snippet/snippetParser'; <del> import { getLeadingWhitespace, commonPrefixLength, isFalsyOrWhitespace } from 'vs/base/common/strings'; </del> <ins> import { getLeadingWhitespace, commonPrefixLength, isFalsyOrWhitespace, pad } from 'vs/base/common/strings'; </ins> import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; export const KnownSnippetVariableNames = Object.freeze({ <ins> 'CURRENT_YEAR': true, 'CURRENT_YEAR_SHORT': true, 'CURRENT_MONTH': true, 'CURRENT_DATE': true, 'CURRENT_HOUR': true, 'CURRENT_MINUTE': true, 'CURRENT_SECOND': true, </ins> 'SELECTION': true, 'CLIPBOARD': true, 'TM_SELECTED_TEXT': true,

} } } <ins> export class TimeBasedVariableResolver implements VariableResolver { resolve(variable: Variable): string { const { name } = variable; if (name === 'CURRENT_YEAR') { return String(new Date().getFullYear()); } else if (name === 'CURRENT_YEAR_SHORT') { return String(new Date().getFullYear()).slice(-2); } else if (name === 'CURRENT_MONTH') { return pad((new Date().getMonth().valueOf() + 1), 2); } else if (name === 'CURRENT_DATE') { return pad(new Date().getDate().valueOf(), 2); } else if (name === 'CURRENT_HOUR') { return pad(new Date().getHours().valueOf(), 2); } else if (name === 'CURRENT_MINUTE') { return pad(new Date().getMinutes().valueOf(), 2); } else if (name === 'CURRENT_SECOND') { return pad(new Date().getSeconds().valueOf(), 2); } return undefined; } } </ins>

import { isWindows } from 'vs/base/common/platform'; import URI from 'vs/base/common/uri'; import { Selection } from 'vs/editor/common/core/selection'; <del> import { SelectionBasedVariableResolver, CompositeSnippetVariableResolver, ModelBasedVariableResolver, ClipboardBasedVariableResolver } from 'vs/editor/contrib/snippet/snippetVariables'; </del> <ins> import { SelectionBasedVariableResolver, CompositeSnippetVariableResolver, ModelBasedVariableResolver, ClipboardBasedVariableResolver, TimeBasedVariableResolver } from 'vs/editor/contrib/snippet/snippetVariables'; </ins> import { SnippetParser, Variable, VariableResolver } from 'vs/editor/contrib/snippet/snippetParser'; import { TextModel } from 'vs/editor/common/model/textModel'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';

resolver = new ClipboardBasedVariableResolver(clipboardService, 0, 2); assertVariableResolve(resolver, 'CLIPBOARD', 'line1'); }); <ins> function assertVariableResolve3(resolver: VariableResolver, varName: string) { const snippet = new SnippetParser().parse(`$${varName}`); const variable = <Variable>snippet.children[0]; assert.equal(variable.resolve(resolver), true, `${varName} failed to resolve`); } test('Add time variables for snippets #41631', 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'); }); </ins> });