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.

[v6] Support string format "time"

See original GitHub issue

A new string format, time, is being added to autorest.

Background

The idea behind time is that it represents time in a way that’s completely agnostic to the date.

What do other SDKs do?

In Python, there is a datetime.time class that contains the hours, minutes, seconds, and microseconds fields. Python accepts this type as input from a user and converts it into a string over the wire: HH:MM:SS.microseconds. Python also converts this string into a datetime.time object when giving a response back to the user.

Issues in JavaScript

In JavaScript we only have the Date class to represent time. While we can set the relevant fields on it, we can’t decouple the time from the date.

Potential solutions

Treat format: “time” as a string.

In this solution, the code generator treats format: “time” (TimeSchema) as a regular string. We can add documentation to the generated types that indicates the format the string should be in. Pros

  • Input/Output is human readable
  • No changes to core-http required

Cons

  • User has to parse the string themselves if they want to work with it.

Create a “Time” interface

With this solution, we create a Time (name up for discussion) interface in core-http that looks roughly like:

interface Time {
  hours: number;
  minutes: number;
  seconds: number;
  microseconds?: number;
}

We would need to update core-http to recognize the time format and serialize/deserialize the Time object the user passes in appropriately.

Pros

  • User can work with the components of time with type-safety.

Cons

  • Changes to core-http required.

References:

Test swagger update: https://github.com/Azure/autorest.testserver/pull/163

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
chradekcommented, Apr 9, 2020

I could do a string for now, that’s definitely the easiest. We can add a flag to autorest.typescript to treat “time” as an interface that aligns with Temporal (or even Temporal itself) in the future if we want to support that for future SDKs.

0reactions
joheredicommented, Jul 7, 2020

Support for this was added by PR#614

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fastest way of converting IPv6 dotted format string to colon ...
What is the fastest way of converting the dotted format of the following IP from version 6 to colon format?? ... I just...
Read more >
Standard date and time format strings | Microsoft Learn
Learn how to use a standard date and time format string to define the text representation of a date and time value in...
Read more >
Format of the time string Uni Erlangen (NTP) - Meinberg
Format of the time string Uni Erlangen (NTP) ; the day of the week (1..7, 1 = Monday) · the current time: hh,...
Read more >
Date Variable Formatting — ExpressionEngine 6 Documentation
Many tags, including channel fields of the “date” type, are designed to display dates and times. The output of these tags can be...
Read more >
Support for property types ipv4, ipv6 and date-time in example ...
Describe the solution you'd like. Swagger UI should know the types ipv4, ipv6 and date-time and fill them with example IPs and the...
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