Merge pull request #1883 from omnivore-app/fix/local-datetime

Use local timezone for the date in the reader
This commit is contained in:
Jackson Harper
2023-03-09 17:05:26 +08:00
committed by GitHub
2 changed files with 8 additions and 4 deletions

View File

@ -1,9 +1,9 @@
import {
ModalRoot,
ModalContent,
ModalOverlay,
ModalRoot,
} from '../../elements/ModalPrimitives'
import { VStack, HStack, Box, SpanBox } from '../../elements/LayoutPrimitives'
import { Box, HStack, SpanBox, VStack } from '../../elements/LayoutPrimitives'
import { Button } from '../../elements/Button'
import { StyledText } from '../../elements/StyledText'
@ -237,7 +237,7 @@ function EditItemModal(props: EditItemModalProps): JSX.Element {
<StyledText css={titleStyle}>SAVED AT:</StyledText>
<FormInput
type="datetime-local"
value={props.savedAt.format('YYYY-MM-DDThh:mm')}
value={props.savedAt.format('YYYY-MM-DDTHH:mm')}
placeholder="Edit Date"
onChange={(event) => {
const dateStr = event.target.value
@ -255,7 +255,7 @@ function EditItemModal(props: EditItemModalProps): JSX.Element {
type="datetime-local"
value={
props.publishedAt
? props.publishedAt.format('YYYY-MM-DDThh:mm')
? props.publishedAt.format('YYYY-MM-DDTHH:mm')
: undefined
}
placeholder="Edit Published Date"

View File

@ -1,15 +1,19 @@
//https://github.com/you-dont-need/You-Dont-Need-Momentjs
const locale = Intl.DateTimeFormat().resolvedOptions().locale || 'en-US'
// get the user's time zone
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
export function formattedLongDate(rawDate: string): string {
return new Intl.DateTimeFormat(locale, {
dateStyle: 'long',
timeZone,
}).format(new Date(rawDate))
}
export function formattedShortDate(rawDate: string): string {
return new Intl.DateTimeFormat(locale, {
dateStyle: 'short',
timeZone,
}).format(new Date(rawDate))
}