Content-Length: 107962 | pFad | https://gist.github.com/JacobWeisenburger/551056d658b3cc7cba4901b1e9eb666b

D8 TemporalDateUtils.ts · GitHub
Skip to content

Instantly share code, notes, and snippets.

@JacobWeisenburger
Last active December 21, 2022 22:02
Show Gist options
  • Save JacobWeisenburger/551056d658b3cc7cba4901b1e9eb666b to your computer and use it in GitHub Desktop.
Save JacobWeisenburger/551056d658b3cc7cba4901b1e9eb666b to your computer and use it in GitHub Desktop.
import { Temporal } from 'temporal'
const TemporalDateUtils = ( datelike: string | Date ) => {
const date = typeof datelike === 'string' ? new Date( datelike ) : datelike
const datelikeString = typeof datelike === 'string' ? datelike : date.toISOString()
const instant = Temporal.Instant.from( date.toISOString() )
const plainDateString = instant.toString().split( 'T' )[ 0 ]
const timeIncluded = /T\d+/.test( datelikeString )
const toPlainDate = () => Temporal.PlainDate.from( plainDateString )
const toPlainDateTime = () => Temporal.PlainDateTime.from(
timeIncluded
? instant.toString().replaceAll( 'Z', '' )
: toPlainDate()
)
return {
toPlainDate,
toPlainDateTime,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://gist.github.com/JacobWeisenburger/551056d658b3cc7cba4901b1e9eb666b

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy