-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Date: Add timezone hint * Update snapshot * Fallback to UTC + offset when there are no timezone abbreviations * Split out in separate component Props @marekhrabe. * Only display when user timezone differs from site timezone Props @joedolson. * Experiment setting the timezone abbr from PHP The system timezone already comes from PHP site, specifically from wp.date.setSettings call in wp-includes/script-loader.php This uses the get_option() to grab the string and setting and surfaces them to the wp-date package. This commit adds an additional property called `abbr` which is the short timezone such as EDT or PST, this is calculated using the PHP date and time functions. * PHP lint fixes * Update package-lock adds packages/date to block-library * Account for timezones without abbreviations Converts `-03` to `UTC-3` for timzones like Argentina/Buenos_Aires. Also updates innline comments. * Return early in filter callback Co-authored-by: Marcus Kazmierczak <[email protected]>
- Loading branch information
Showing
8 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { __experimentalGetSettings as getDateSettings } from '@wordpress/date'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Tooltip from '../tooltip'; | ||
|
||
/** | ||
* Displays timezone information when user timezone is different from site timezone. | ||
*/ | ||
const TimeZone = () => { | ||
const { timezone } = getDateSettings(); | ||
|
||
// Convert timezone offset to hours. | ||
const userTimezoneOffset = -1 * ( new Date().getTimezoneOffset() / 60 ); | ||
|
||
// System timezone and user timezone match, nothing needed. | ||
// Compare as numbers because it comes over as string. | ||
if ( Number( timezone.offset ) === userTimezoneOffset ) { | ||
return null; | ||
} | ||
|
||
const offsetSymbol = timezone.offset >= 0 ? '+' : ''; | ||
const zoneAbbr = | ||
'' !== timezone.abbr && isNaN( timezone.abbr ) | ||
? timezone.abbr | ||
: `UTC${ offsetSymbol }${ timezone.offset }`; | ||
|
||
const timezoneDetail = | ||
'UTC' === timezone.string | ||
? __( 'Coordinated Universal Time' ) | ||
: `(${ zoneAbbr }) ${ timezone.string.replace( '_', ' ' ) }`; | ||
|
||
return ( | ||
<Tooltip position="top center" text={ timezoneDetail }> | ||
<div className="components-datetime__timezone">{ zoneAbbr }</div> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default TimeZone; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters