Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[BUG]: ISO 8601 date string inferred as String? instead of DateTime in Dart output

Đang mở
#3,533 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
dart, typescript
Lĩnh vực
compilers, tooling

Hướng nghiên cứu

Reproduce the issue in app.quicktype.io and the quicktype CLI with the supplied JSON and Dart target, checking whether the “Detect dates & times” option is enabled. Trace the date-format inference and Dart generation path; done means the timestamp is inferred as DateTime (or DateTime? with nullability) and the generated code parses and serializes it accordingly.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

ISO 8601 date string inferred as String? instead of DateTime in Dart output

Issue Type

Quicktype output / Type inference issue

Context (Environment, Version, Language)

Input Format: JSON
Output Language: Dart

CLI, npm, or app.quicktype.io: app.quicktype.io / CLI
Version: Latest

Description

ISO 8601 formatted date-time strings (e.g., "2025-08-19T08:08:45.087") are currently being typed as optional String? rather than being detected as DateTime types in Dart code generation. Older versions of quicktype automatically recognized ISO date strings and generated DateTime.parse() / toIso8601String() methods.

Input Data

{
  "LastRecorded": "2025-08-19T08:08:45.087"
}

Expected Behaviour / Output

ISO date-time strings should be inferred as DateTime (or DateTime? if nullability is enabled), producing parsing logic like:

import 'dart:convert';

Welcome welcomeFromJson(String str) => Welcome.fromJson(json.decode(str));

String welcomeToJson(Welcome data) => json.encode(data.toJson());

class Welcome {
    DateTime lastRecorded;

    Welcome({
        required this.lastRecorded,
    });

    factory Welcome.fromJson(Map<String, dynamic> json) => Welcome(
        lastRecorded: DateTime.parse(json["LastRecorded"]),
    );

    Map<String, dynamic> toJson() => {
        "LastRecorded": lastRecorded.toIso8601String(),
    };
}

Current Behaviour / Output

The field is treated as a generic nullable String?:

import 'dart:convert';

Temperatures temperaturesFromJson(String str) => Temperatures.fromJson(json.decode(str));

String temperaturesToJson(Temperatures data) => json.encode(data.toJson());

class Temperatures {
    String? lastRecorded;

    Temperatures({
        this.lastRecorded,
    });

    factory Temperatures.fromJson(Map<String, dynamic> json) => Temperatures(
        lastRecorded: json["LastRecorded"],
    );

    Map<String, dynamic> toJson() => {
        "LastRecorded": lastRecorded,
    };
}

Steps to Reproduce

  1. Open app.quicktype.io (or run quicktype CLI).
  2. Set target language to Dart.
  3. Input JSON containing an ISO 8601 timestamp: {"LastRecorded": "2025-08-19T08:08:45.087"}.
  4. Observe that lastRecorded is generated as String? instead of DateTime.

Possible Solution

Ensure string format inference checks ISO 8601 patterns prior to defaulting to String for Dart generation, or verify that the "Detect dates & times" option setting is active in the Dart target options.

Ngôn ngữ chính
TypeScript
Star
13.9k
Fork
1.2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của glideapps/quicktype

Tất cả issue của glideapps/quicktype

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.