-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stats: Use moment object with site offset (#96484)
* use moment object with offset * add hook for site zone moment
- Loading branch information
Showing
4 changed files
with
51 additions
and
10 deletions.
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
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,23 @@ | ||
import moment, { Moment } from 'moment'; | ||
import { useLocalizedMoment } from 'calypso/components/localized-moment'; | ||
import { useSelector } from 'calypso/state'; | ||
import { getSiteOption } from 'calypso/state/sites/selectors'; | ||
import { getSelectedSiteId } from 'calypso/state/ui/selectors'; | ||
|
||
export function getMomentSiteZone( | ||
state: object, | ||
siteId: number | null, | ||
localizedMoment?: () => Moment | ||
) { | ||
const gmtOffset = getSiteOption( state, siteId, 'gmt_offset' ) as number; | ||
return ( localizedMoment || moment )().utcOffset( gmtOffset ?? 0 ); | ||
} | ||
|
||
/** | ||
* Get moment object based on site timezone. | ||
*/ | ||
export default function useMomentSiteZone() { | ||
const siteId = useSelector( getSelectedSiteId ); | ||
const localizedMoment = useLocalizedMoment(); | ||
return useSelector( ( state ) => getMomentSiteZone( state, siteId, localizedMoment ) ); | ||
} |
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