From 3eea884fbbf7e2fed7566ba0be205936259d75c7 Mon Sep 17 00:00:00 2001 From: yash-chowdhary Date: Sun, 1 Mar 2020 21:11:56 +0800 Subject: [PATCH 1/5] Allow custom timezone to be used to set the timestamp --- src/Site.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Site.js b/src/Site.js index 0fbe178e8c..3fba1cd2ef 100644 --- a/src/Site.js +++ b/src/Site.js @@ -1014,7 +1014,17 @@ class Site { } _setTimestampVariable() { - const time = new Date().toUTCString(); + const timeZone = this.siteConfig.timeZone ? this.siteConfig.timeZone : 'UTC'; + const locale = this.siteConfig.locale ? this.siteConfig.locale : 'en-GB'; + const options = { + weekday: 'short', + year: 'numeric', + month: 'short', + day: 'numeric', + timeZone, + timeZoneName: 'short', + }; + const time = new Date().toLocaleTimeString(locale, options); Object.keys(this.userDefinedVariablesMap).forEach((base) => { this.userDefinedVariablesMap[base].timestamp = time; }); From 1bd90e45e94ceef0585dec736a2be40cfcd5c08e Mon Sep 17 00:00:00 2001 From: yash-chowdhary Date: Sun, 1 Mar 2020 22:02:26 +0800 Subject: [PATCH 2/5] Update user guide --- docs/site.json | 1 + docs/userGuide/syntax/variables.mbdf | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/site.json b/docs/site.json index 91ab123fe4..81184cf5f7 100644 --- a/docs/site.json +++ b/docs/site.json @@ -1,5 +1,6 @@ { "baseUrl": "", + "timeZone": "Asia/Singapore", "titlePrefix": "MarkBind", "pages": [ { diff --git a/docs/userGuide/syntax/variables.mbdf b/docs/userGuide/syntax/variables.mbdf index fcbcb4b27a..7c68212fd5 100644 --- a/docs/userGuide/syntax/variables.mbdf +++ b/docs/userGuide/syntax/variables.mbdf @@ -56,7 +56,21 @@ Represents the root directory of the project. Used for specifying intra-site lin ##### Built-in Variable: `timestamp` -{{ timestamp }} is the time stamp (in UTC) that indicates when the page was generated. +{{ timestamp }} is the time stamp that indicates when the page was generated. + +You can set the time zone and locale in `site.json` like so - + +```js +site.json +{ + ... + "timeZone": "Asia/Singapore", + "locale": "en-US", + ... +} +``` + +The default values of `"timeZone"` and `"locale"` are `"UTC"` and `"en-GB"` respectively.
From 0188bda02cac5ca40d1cad865ac4afe59187449e Mon Sep 17 00:00:00 2001 From: yash-chowdhary Date: Mon, 2 Mar 2020 22:10:27 +0800 Subject: [PATCH 3/5] Update user guide --- docs/userGuide/siteConfiguration.md | 8 ++++++++ docs/userGuide/syntax/variables.mbdf | 14 ++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/userGuide/siteConfiguration.md b/docs/userGuide/siteConfiguration.md index 9d40769090..f072227a0b 100644 --- a/docs/userGuide/siteConfiguration.md +++ b/docs/userGuide/siteConfiguration.md @@ -198,3 +198,11 @@ The example above uses tags as an example of configuring plugin settings, refer #### **`enableSearch`** **Specifies that the website should use MarkBind's search functionality.** Default: `true`. See [User Guide: Making the Site Searchable](makingTheSiteSearchable.html) for more details. + +#### **`timeZone`** + +**Time zone of the time stamp that indicates when the page was generated.** Default: `"UTC"`. See [User Guide: Built-in Variable: `timestamp`](reusingContents.html#built-in-variable-timestamp) for more details. + +#### **`locale`** + +**Language by locale used for the time stamp.** Default: `"en-GB"`. The date format is thus -
`, , <24-hour Time>