swagger-api / swagger-api/swagger-codegen

DateTime Format is not Culture Invariant

Open
#7,436 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Serverside expects DateTimeFormat in "dd/MM/yyyy"
As my client system has culture "de-CH", Setting the Clients DateTimeFormat to "dd/MM/yyyy"
Will still lead to formatting the Date in the following Format: "dd.MM.yyyy". The following format string will work: "dd'/'MM'/'yyyy"

See custom format specifier: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

Client Code Generation: CSharp

Swagger-codegen version

master

Swagger declaration file content or url

Applies to any date

  • in: header
    name: bis
    description: >-
    Tag, bis dem die angegebene Aenderung gelten soll. Wenn nicht
    vorhanden gilt die Aenderung bis alle Ewigkeit
    required: false
    type: string
    format: date
Command line used for generation
Steps to reproduce

any date time formatting

Related issues/PRs

None found

Suggest a fix/enhancement

https://github.com/swagger-api/swagger-codegen/blob/2fd38fbbe286980b0c6c7d063da6aa080935cd96/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache#L292

Suggestion:
This would in any circumstances lead to the specified format:
return ((DateTime)obj).ToString (Configuration.DateTimeFormat, CultureInfo.InvariantCulture);

Contributor guide

Open the contributing guide

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

Start at modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache around line 292, where the issue identifies DateTime formatting. Reproduce generation with a de-CH culture and a date format of dd/MM/yyyy; done means the generated C# client preserves the configured separators regardless of the client culture.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.