Skip to content

Make parse safer #15

Closed
Closed
@paulyoung

Description

@paulyoung

I was originally doing the following and easily ran into a runtime error because isoString was invalid:

jsDate <- parse isoString
let ms = getTime jsDate

I'm currently doing this instead:

parseJSDate
  :: forall eff
   . String
  -> Eff ( locale :: LOCALE | eff ) (Maybe JSDate)
parseJSDate date = do
  parsed <- parse date
  pure $ if isValid parsed then Just parsed else Nothing
jsDate <- parseJSDate isoString
let ms = getTime <$> jsDate

Is there any reason to not make parse do this by default?

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueFirst-time contributors who are looking to help should work on these issues.type: documentationImprovements or additions to documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions