question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional flag which changes string to date in case of format data-time or date

See original GitHub issue

In the project I am working on, we use openapi v3. The schema contains objects which use the type string with the format date-time.

example:

ExampleType:
  title: ExampleType
  type: object
  properties:
    id:
      type: integer
    validFrom:
      type: string
      format: date-time
      example: "2012-10-27T17:18:30.966Z"

We did not want to convert the date everytime and therefore we created a middleware for the server and client-side that automatically converts it from string to Date. When creating the models via the openapi-typescript-gencode tool, the output models use the type string (as intended). But in our case we need it to be of type Date, which is a special case. Therefore an optional flag to enable this feature would be great.

What is needed?

It needs to remember the format value and in case of date or date-time the output type should be Date instead of string.

About implementing it

I would try to implement it and in case that anyone wants to help me, that would be great.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
ferdikoomencommented, Nov 28, 2020

@Nico i’ve added this to the roadmap, seems like a feature that is worth investigation!

0reactions
NicoVogelcommented, Nov 22, 2020

@ferdikoomen here a the list for the frontends:

Angular

uses JSON.stringify() (source)

axios

uses JSON.stringify() (source)

fetch

has no automatic parsing (source)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Standard date and time format strings | Microsoft Learn
The "O" or "o" standard format specifier represents a custom date and time format string using a pattern that preserves time zone information ......
Read more >
Regex date format validation on Java - Stack Overflow
This code will parse the text, validate that it is a valid date, and also return the date as a LocalDate object. Note...
Read more >
Format Dates - Trifacta Documentation
Option 2 - Patterns based on date format · Set the column's Datetime format to: M/d/yyyy . · Select the green bar in...
Read more >
Forcing a FORMAT on CAST for Converting Character to DATE
You can use a FORMAT phrase to convert a character string that does not match the format of the target DATE data type....
Read more >
Format elements | BigQuery - Google Cloud
The date in the format %Y-%m-%d. 2021-01-20. %G, DATE DATETIME TIMESTAMP
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found