Skip to content

Add TimeOfDay compareTo() function #139098

@subzero911

Description

@subzero911

Is there an existing issue for this?

Use case

Unlike DateTime, TimeOfDay does not have compareTo() method.
In order to compare 2 TimeOfDay objects, you have to use this awkward way:

  1. Create a helper extension:
extension TimeOfDayExt on TimeOfDay {
  /// note: 'hour' is in 24-hour format
  double toDouble() => hour + minute/60.0;
}
  1. Convert both TimeOfDay's to double:
    final double nowTime = TimeOfDay.now().toDouble();
    final double deadlineTime = TimeOfDay.fromDateTime(deadline).toDouble();
  1. Compare these doubles:
if (nowTime >= deadlineTime) {
    // you're fired
}

Proposal

Add a compareTo() method for TimeOfDay, so we can compare them directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions