Skip to content

Commit dfb4d6d

Browse files
committed
implement Intl.DateTimeFormat for PHP style e format char
1 parent e4338f7 commit dfb4d6d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ $("div#clock").clock({"timeFormat": timeFmtOptions});
7676
## Format Date and Time using PHP style Format Characters
7777

7878
There are two options that allow us to use PHP style Format Characters:
79-
* "dateFormat" -> for formatting the date string
80-
* "timeFormat" -> for formatting the time string
79+
* `dateFormat` -> for formatting the date string
80+
* `timeFormat` -> for formatting the time string
8181

82-
PHP Style Format Characters (such as those found [here](http://php.net/manual/en/function.date.php "PHP Format Characters")) supported by the ***dateFormat*** parameter are:
82+
PHP Style Format Characters (such as those found [here](https://www.php.net/manual/en/datetime.format.php "PHP Format Characters")) supported by the ***dateFormat*** parameter are:
8383

8484
| Format Character | Description | Example Returned values |
8585
| ----------------- | ------------------------------------------ | ------------------- |
@@ -111,7 +111,7 @@ $("div#clock").clock({"dateFormat":"D, F n, Y"});
111111
```
112112

113113

114-
PHP Style Format Characters (such as those found [here](http://php.net/manual/en/function.date.php "PHP Format Characters")) supported by the ***timeFormat*** parameter are:
114+
PHP Style Format Characters (such as those found [here](https://www.php.net/manual/en/datetime.format.php "PHP Format Characters")) supported by the ***timeFormat*** parameter are:
115115

116116
| Format Character | Description | Example Returned values |
117117
| ----------------- | ------------------------------------------ | ----------------- |

jqClock.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
* @timestamp defaults to clients current time, using the performance API
1212
* @timezone defaults to detection of client timezone, but can be passed in as a string such as "UTC-6" when using server generated timestamps
1313
* @locale defaults to navigator language else "en", possible values are: "af", "am", "ar", "bg", "bn", "ca", "cs", "da", "de", "el", "en", "es", "et", "fa", "fi", "fr", "gu", "he", "hi", "hr", "hu", "id", "in", "it", "iw", "ja", "kn", "ko", "lt", "lv", "ml", "mo", "mr", "ms", "nb", "nl", "no", "pl", "pt", "ro", "ru", "sh", "sk", "sl", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "ur", "vi", "zh", "arb", "cmn", "cnr", "drw", "ekk", "fil", "lvs", "pes", "prs", "swc", "swh", "tnf", "zsm" (can optionally add region)
14-
* @calendar defaults to "true", possible value are: boolean "true" or "false"
15-
* @dateFormat defaults to Intl.DateTimeFormat options object { "dateStyle": "full" }; can take string with PHP style format characters; if set to false @calendar will be false
14+
* @dateFormat defaults to Intl.DateTimeFormat options object { "dateStyle": "full" }; can take string with PHP style format characters; if set to false will remove calendar output
1615
* @timeFormat defaults to Intl.DateTimeFormat options object { "timeStyle": "medium" }; can take string with PHP style format characters;
1716
* @isDST possible values are boolean `true` or `false`, if not passed in will be calculated based on client time (default)
1817
*
@@ -400,7 +399,10 @@ if (!Number.prototype.map) {
400399

401400
//TIMEZONE
402401
//Timezone identifier
403-
"e": ( clk ) => clk.myoptions.timezone,
402+
"e": ( clk ) => /(UTC|GMT)\+/.test( clk.myoptions.timezone ) ? clk.myoptions.timezone : new Intl.DateTimeFormat( clk.myoptions.locale, {
403+
timeZone: clk.myoptions.timezone,
404+
timeZoneName: "long"
405+
} ).formatToParts( clk.mytimestamp_sysdiff ).filter(e => e.type === 'timeZoneName')[0].value,
404406
//Whether or not the date is in daylight saving time
405407
"I": ( clk ) => clk.myoptions.isDST ? "DST" : "",
406408
//Difference to Greenwich time (GMT) in hours

0 commit comments

Comments
 (0)