-
Notifications
You must be signed in to change notification settings - Fork 56
/
ConvertTimestamp.ps1
31 lines (23 loc) · 1.37 KB
/
ConvertTimestamp.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<#
.SYNOPSIS
This script converts a Git commit timestamp to a human-readable date format and is intended for use in build processes.
.DESCRIPTION
The script takes a Git commit timestamp as input and converts it into a standardized date format ("yyyy-MM-ddTHH:mm:ssK"). It's designed to be run as part of an automated build process, specifically within MSBuild tasks, to generate and use date information from Git commits.
.NOTES
The script is intended to be called from an MSBuild task, but can be used in any context where a Git commit timestamp needs to be converted to a human-readable date.
.EXAMPLE
pwsh -NoProfile -ExecutionPolicy Bypass -File "ConvertTimestamp.ps1" -GitCommitTimestamp <timestamp>
This example shows how to call the script from an MSBuild task, passing a Git commit timestamp as an argument. The `-NoProfile` and `-ExecutionPolicy Bypass` flags ensure a clean and unrestricted execution environment.
.AUTHOR
Steven T. Cramer
#>
# Assuming GitCommitTimestamp is passed as an argument to the script
param(
[int64]$GitCommitTimestamp
)
# Convert GitCommitTimestamp to a human-readable date
$epochStart = New-Object System.DateTime(1970, 1, 1, 0, 0, 0, [System.DateTimeKind]::Utc)
$commitDate = $epochStart.AddSeconds($GitCommitTimestamp)
$formattedDate = $commitDate.ToString("yyyy-MM-ddTHH:mm:ssK")
# Output or use the formatted date as needed
Write-Output $formattedDate