Skip to content

Commit

Permalink
implement Intl.DateTimeFormat for PHP style e format char
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Mar 18, 2024
1 parent e4338f7 commit dfb4d6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ $("div#clock").clock({"timeFormat": timeFmtOptions});
## Format Date and Time using PHP style Format Characters

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

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:
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:

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


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:
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:

| Format Character | Description | Example Returned values |
| ----------------- | ------------------------------------------ | ----------------- |
Expand Down
8 changes: 5 additions & 3 deletions jqClock.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
* @timestamp defaults to clients current time, using the performance API
* @timezone defaults to detection of client timezone, but can be passed in as a string such as "UTC-6" when using server generated timestamps
* @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)
* @calendar defaults to "true", possible value are: boolean "true" or "false"
* @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
* @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
* @timeFormat defaults to Intl.DateTimeFormat options object { "timeStyle": "medium" }; can take string with PHP style format characters;
* @isDST possible values are boolean `true` or `false`, if not passed in will be calculated based on client time (default)
*
Expand Down Expand Up @@ -400,7 +399,10 @@ if (!Number.prototype.map) {

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

0 comments on commit dfb4d6d

Please sign in to comment.