Skip to content

Commit

Permalink
Also display build timestamp in user's timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin committed Jul 31, 2023
1 parent 5df4415 commit 46b8112
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion layouts/shortcodes/site-build-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{{ $isNetlifyBuilt := os.Getenv "NETLIFY" | default false -}}
{{ $isPR := os.Getenv "PULL_REQUEST" -}}
{{ $reviewID := os.Getenv "REVIEW_ID" -}}
{{ $now := now -}}

Netlify build information:

Expand All @@ -17,7 +18,7 @@ Netlify built | `{{ $isNetlifyBuilt }}`

{{/* Don't show timestamp for local builds to avoid affecting site diffs. */ -}}
{{ with $isNetlifyBuilt -}}
Date/time[^date] | {{ now.Format "2006-01-02 15:04 MST" }}
Date/time[^date] | {{ $now.Format "2006-01-02 15:04 MST" }}[^local-time]
{{ end -}}
{{/* */ -}}

Expand Down Expand Up @@ -55,3 +56,12 @@ Deploy context | {{ os.Getenv "CONTEXT" | default "local" }}
{{/* End of table */}}

[^date]: Approximate build timestamp.
[^local-time]: In your timezone: <span id="local-time">unknown</span>.

<script>
document.addEventListener("DOMContentLoaded", function() {
var options = { hour: '2-digit', hour12: false, minute: '2-digit', timeZoneName: 'short' };
var buildDate = new Date("{{ $now.Format "2006-01-02T15:04:05Z07:00" }}");
document.getElementById("local-time").innerText = buildDate.toLocaleString(undefined, options);
});
</script>

0 comments on commit 46b8112

Please sign in to comment.