-
-
Couldn't load subscription status.
- Fork 8
Add datetime formatting capability to variable set task #777
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
base: main
Are you sure you want to change the base?
Changes from all commits
448ed50
766d6e4
6a933f7
c94b8fc
0e0e077
363bc9f
ee915b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,3 +200,4 @@ _Pvt_Extensions | |
| /.cr | ||
| /*/v[0-9]/*.js | ||
| /*/v[0-9]/*.js.map | ||
| ./*/v[0-9]/*.tsbuildinfo | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"root":["./vsts-variable-set.ts"],"version":"5.8.3"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"root":["./vsts-variable-set.ts"],"version":"5.8.3"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"root":["./vsts-variable-set.ts"],"version":"5.8.3"} |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,47 @@ | |||||
|
|
||||||
| const variable = tl.getInput("VariableName", true); | ||||||
|
|
||||||
| function formatDateTime(format: string): string { | ||||||
| const now = new Date(); | ||||||
|
|
||||||
| // Simple and robust approach - only support explicit multi-character patterns | ||||||
| // This avoids conflicts with single characters in normal text | ||||||
| let formatted = format; | ||||||
|
|
||||||
| // Year patterns | ||||||
| formatted = formatted.replace(/yyyy/g, now.getFullYear().toString()); | ||||||
| formatted = formatted.replace(/yy/g, now.getFullYear().toString().slice(-2)); | ||||||
|
|
||||||
| // Month patterns (2-digit and single digit with leading zero requirement) | ||||||
| const month = (now.getMonth() + 1).toString().padStart(2, '0'); | ||||||
| formatted = formatted.replace(/MM/g, month); | ||||||
|
|
||||||
| // Day patterns | ||||||
| const day = now.getDate().toString().padStart(2, '0'); | ||||||
| formatted = formatted.replace(/dd/g, day); | ||||||
|
|
||||||
| // Hour 24-hour patterns | ||||||
| const hour = now.getHours().toString().padStart(2, '0'); | ||||||
| formatted = formatted.replace(/HH/g, hour); | ||||||
|
|
||||||
| // Hour 12-hour patterns | ||||||
| const hour12 = (now.getHours() % 12 || 12).toString().padStart(2, '0'); | ||||||
| formatted = formatted.replace(/hh/g, hour12); | ||||||
|
|
||||||
| // Minute patterns | ||||||
| const minute = now.getMinutes().toString().padStart(2, '0'); | ||||||
| formatted = formatted.replace(/mm/g, minute); | ||||||
|
|
||||||
| // Second patterns | ||||||
| const second = now.getSeconds().toString().padStart(2, '0'); | ||||||
| formatted = formatted.replace(/ss/g, second); | ||||||
|
|
||||||
| // AM/PM patterns | ||||||
| formatted = formatted.replace(/tt/g, now.getHours() >= 12 ? 'PM' : 'AM'); | ||||||
|
|
||||||
| return formatted; | ||||||
| } | ||||||
|
|
||||||
| function getValue() | ||||||
| { | ||||||
| const from = tl.getInput("From") || "value"; | ||||||
|
|
@@ -15,6 +56,11 @@ function getValue() | |||||
| { | ||||||
| return process.env[tl.getInput("Env", true)]; | ||||||
| } | ||||||
| case "datetime": | ||||||
| { | ||||||
| const format = tl.getInput("DateTimeFormat", true) || "yyyy-MM-dd HH:mm:ss"; | ||||||
|
||||||
| const format = tl.getInput("DateTimeFormat", true) || "yyyy-MM-dd HH:mm:ss"; | |
| const format = tl.getInput("DateTimeFormat", true); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"root":["./vsts-variable-transform.ts"],"version":"5.8.3"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"root":["./vsts-variable-transform.ts"],"version":"5.8.3"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"root":["./vsts-variable-transform.ts"],"version":"5.8.3"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hh pattern for 12-hour format is not documented in the task.json helpMarkdown. The help text only mentions HH (24-hour) but not hh (12-hour).