Download wp-calypso/client/lib/jetpack/hooks/use-date-with-offset.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/jetpack/hooks/use-date-with-offset.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/jetpack/hooks/use-date-with-offset.ts
-
curl -L -o use-date-with-offset.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/jetpack/hooks/use-date-with-offset.ts
1.22 kB
| import { Moment } from 'moment'; | |
| import { useMemo } from 'react'; | |
| import { applySiteOffset } from 'calypso/lib/site/timezone'; | |
| import { useSelector } from 'calypso/state'; | |
| import getSiteGmtOffset from 'calypso/state/selectors/get-site-gmt-offset'; | |
| import getSiteTimezoneValue from 'calypso/state/selectors/get-site-timezone-value'; | |
| import getSelectedSiteId from 'calypso/state/ui/selectors/get-selected-site-id'; | |
| // Tolerates null settings values, unlike the implementation in `calypso/components/site-offset`; | |
| // I don't want to disturb existing behavior, but we may want to come back later | |
| // and DRY up this bit of code. | |
| export default function useDateWithOffset( | |
| date: Moment | undefined | null, | |
| { keepLocalTime = false } = {} | |
| ): Moment | undefined { | |
| const siteId = useSelector( getSelectedSiteId ); | |
| const timezone = useSelector( ( state ) => | |
| siteId ? getSiteTimezoneValue( state, siteId ) : null | |
| ); | |
| const gmtOffset = useSelector( ( state ) => | |
| siteId ? getSiteGmtOffset( state, siteId ) : null | |
| ); | |
| const dateWithOffset = useMemo( | |
| () => ( date ? applySiteOffset( date, { timezone, gmtOffset, keepLocalTime } ) : undefined ), | |
| [ date, timezone, gmtOffset, keepLocalTime ] | |
| ); | |
| return dateWithOffset; | |
| } | |