Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Pr2235/follow up (#2239)
Browse files Browse the repository at this point in the history
* New utils/time function formatDateWithTimezone

* Refactored CanUserClaimMessage component to use formatDateWithTimezone

Co-authored-by: Leandro <[email protected]>
  • Loading branch information
alfetopito and Leandro authored Jan 21, 2022
1 parent edac11d commit d0cfce8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/custom/pages/Claim/CanUserClaimMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IntroDescription } from './styled'
import { ClaimCommonTypes } from './types'
import { useClaimDispatchers, useClaimState, useClaimTimeInfo } from 'state/claim/hooks'
import { ClaimStatus } from 'state/claim/actions'
import { formatDateWithTimezone } from 'utils/time'

type ClaimIntroductionProps = Pick<ClaimCommonTypes, 'hasClaims'> & {
isAirdropOnly: boolean
Expand All @@ -26,10 +27,7 @@ export default function CanUserClaimMessage({ hasClaims, isAirdropOnly }: ClaimI
<Trans>
Thank you for being a supporter of CowSwap and the CoW protocol. As an important member of the CowSwap
Community you may claim vCOW to be used for voting and governance. You can claim your tokens until{' '}
<i>
{airdropDeadline && new Date(airdropDeadline).toLocaleString()} (
{Intl.DateTimeFormat().resolvedOptions().timeZone})
</i>
<i>{formatDateWithTimezone(airdropDeadline)}</i>
<ExternalLink href="https://cow.fi/">Read more about vCOW</ExternalLink>
</Trans>
</p>
Expand Down
13 changes: 13 additions & 0 deletions src/custom/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@
export function getDateTimestamp(date: Date): number {
return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime()
}

/**
* Helper function that returns a given Date/timestamp as a locale representation of it as string
* in the format <local date string> (<time zone information>)
*/
export function formatDateWithTimezone(date: Date | number | undefined | null): string | undefined {
if (!date) {
return
}
const _date = date instanceof Date ? date : new Date(date)

return `${_date.toLocaleString()} (${Intl.DateTimeFormat().resolvedOptions().timeZone})`
}

0 comments on commit d0cfce8

Please sign in to comment.