fsprojects / fsprojects/FSharpPlus

[API Proposal]: DateTime/DateTimeOffset format

Open
#644 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
F#
Stars
941
Forks
106
PR merge metrics
No merged PRs in 30d

Description

Background and motivation

There is currently formats related to DateTime:

"yyyy-MM-ddTHH:mm:ss.fffZ"; "yyyy-MM-ddTHH:mm:ssZ"

and DateTimeOffset:

"yyyy-MM-ddTHH:mm:ss.fffK"; "yyyy-MM-ddTHH:mm:ssK"

These look related to ISO 8601. See the roundtrip format in:

https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings

And the page on the standard on wikipedia:
https://en.wikipedia.org/wiki/ISO_8601

API Proposal

Modules in the Extensions.InvariantCulture namespace named DateTime and DateTimeOffset with related functions. Move the implementation of TryParse and Parse of DateTime and DateTimeOffset to these modules.

namespace FSharpPlus.Extensions.InvariantCulture

[<RequireQualifiedAccess>]
module DateTime =
     let tryParse (x:string) =
        match DateTime.TryParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffZ"; "yyyy-MM-ddTHH:mm:ssZ"|], null, DateTimeStyles.RoundtripKind) with
        | true, x -> Some x
        | _ ->
            match DateTime.TryParse (x, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal) with
            | true, x -> Some x
            | _ -> None
API Usage
open FSharpPlus.Extensions
let parsed = InvariantCulture.DateTime.tryParse stringFromTheInternet
Alternative Designs

No response

Risks

Probably little risk

Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?

Yes, please assign this issue to me.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests. Start by locating the existing DateTime and DateTimeOffset TryParse and Parse implementations, then compare their current formats with the proposed InvariantCulture modules. Done means the API shape and parsing behavior for both types are agreed and implemented, with validation of the proposed formats.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.