Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
eaf9ff73
Unverified
Commit
eaf9ff73
authored
4 years ago
by
renyou
Committed by
GitHub
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Implement Comparable<TimeOfDay> (#59317)" (#59981)
This reverts commit
2933e895
.
parent
a88e2c87
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
83 deletions
+6
-83
time.dart
packages/flutter/lib/src/material/time.dart
+6
-18
time_test.dart
packages/flutter/test/material/time_test.dart
+0
-65
No files found.
packages/flutter/lib/src/material/time.dart
View file @
eaf9ff73
...
...
@@ -48,21 +48,20 @@ enum DayPeriod {
/// * [DateTime], which represents date and time, and is subject to eras and
/// time zones.
@immutable
class
TimeOfDay
implements
Comparable
<
TimeOfDay
>
{
class
TimeOfDay
{
/// Creates a time of day.
///
/// The [hour] argument must be between 0 and 23, inclusive. The [minute]
/// argument must be between 0 and 59, inclusive.
const
TimeOfDay
({
@required
this
.
hour
,
@required
this
.
minute
})
:
assert
(
hour
!=
null
&&
hour
>=
0
&&
hour
<
hoursPerDay
),
assert
(
minute
!=
null
&&
minute
>=
0
&&
minute
<
minutesPerHour
);
const
TimeOfDay
({
@required
this
.
hour
,
@required
this
.
minute
});
/// Creates a time of day based on the given time.
///
/// The [hour] is set to the time's hour and the [minute] is set to the time's
/// minute in the timezone of the given [DateTime].
TimeOfDay
.
fromDateTime
(
DateTime
time
)
:
this
(
hour:
time
.
hour
,
minute:
time
.
minute
);
:
hour
=
time
.
hour
,
minute
=
time
.
minute
;
/// Creates a time of day based on the current time.
///
...
...
@@ -81,6 +80,8 @@ class TimeOfDay implements Comparable<TimeOfDay> {
/// Returns a new TimeOfDay with the hour and/or minute replaced.
TimeOfDay
replacing
({
int
hour
,
int
minute
})
{
assert
(
hour
==
null
||
(
hour
>=
0
&&
hour
<
hoursPerDay
));
assert
(
minute
==
null
||
(
minute
>=
0
&&
minute
<
minutesPerHour
));
return
TimeOfDay
(
hour:
hour
??
this
.
hour
,
minute:
minute
??
this
.
minute
);
}
...
...
@@ -135,19 +136,6 @@ class TimeOfDay implements Comparable<TimeOfDay> {
return
'
$TimeOfDay
(
$hourLabel
:
$minuteLabel
)'
;
}
static
int
_inMinutesOf
(
TimeOfDay
time
)
=>
minutesPerHour
*
time
.
hour
+
time
.
minute
;
@override
int
compareTo
(
TimeOfDay
other
)
{
if
(
other
==
null
)
{
return
1
;
}
if
(
other
==
this
)
{
return
0
;
}
return
_inMinutesOf
(
this
).
compareTo
(
_inMinutesOf
(
other
));
}
}
/// Determines how the time picker invoked using [showTimePicker] formats and
...
...
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/time_test.dart
View file @
eaf9ff73
...
...
@@ -28,69 +28,4 @@ void main() {
expect
(
await
pumpTest
(
true
),
'07:00'
);
});
});
group
(
'TimeOfDay'
,
()
{
test
(
'assertions'
,
()
{
expect
(()
=>
TimeOfDay
(
hour:
null
,
minute:
null
),
throwsAssertionError
);
expect
(()
=>
TimeOfDay
(
hour:
null
,
minute:
0
),
throwsAssertionError
);
expect
(()
=>
TimeOfDay
(
hour:
0
,
minute:
null
),
throwsAssertionError
);
expect
(()
=>
TimeOfDay
(
hour:
-
1
,
minute:
-
1
),
throwsAssertionError
);
expect
(()
=>
TimeOfDay
(
hour:
0
,
minute:
-
1
),
throwsAssertionError
);
expect
(()
=>
TimeOfDay
(
hour:
-
1
,
minute:
0
),
throwsAssertionError
);
expect
(()
=>
TimeOfDay
(
hour:
24
,
minute:
0
),
throwsAssertionError
);
expect
(()
=>
TimeOfDay
(
hour:
0
,
minute:
60
),
throwsAssertionError
);
});
test
(
'.=='
,
()
{
expect
(
const
TimeOfDay
(
hour:
0
,
minute:
0
)
==
(
const
TimeOfDay
(
hour:
0
,
minute:
0
)),
true
);
});
test
(
'.replacing'
,
()
{
expect
(
const
TimeOfDay
(
hour:
23
,
minute:
59
).
replacing
(
hour:
0
),
const
TimeOfDay
(
hour:
0
,
minute:
59
),
);
expect
(
const
TimeOfDay
(
hour:
23
,
minute:
59
).
replacing
(
minute:
0
),
const
TimeOfDay
(
hour:
23
,
minute:
0
),
);
});
test
(
'.compareTo'
,
()
{
expect
(
<
TimeOfDay
>[
const
TimeOfDay
(
hour:
12
,
minute:
0
),
const
TimeOfDay
(
hour:
23
,
minute:
59
),
const
TimeOfDay
(
hour:
0
,
minute:
0
),
]..
sort
(),
<
TimeOfDay
>[
const
TimeOfDay
(
hour:
0
,
minute:
0
),
const
TimeOfDay
(
hour:
12
,
minute:
0
),
const
TimeOfDay
(
hour:
23
,
minute:
59
),
]
);
expect
(
const
TimeOfDay
(
hour:
0
,
minute:
0
).
compareTo
(
null
)
>
0
,
true
);
const
TimeOfDay
zero
=
TimeOfDay
(
hour:
0
,
minute:
0
);
expect
(
zero
.
compareTo
(
zero
),
0
);
expect
(
const
TimeOfDay
(
hour:
0
,
minute:
0
)
.
compareTo
(
const
TimeOfDay
(
hour:
0
,
minute:
0
)),
0
);
expect
(
<
TimeOfDay
>[
const
TimeOfDay
(
hour:
0
,
minute:
0
),
const
TimeOfDay
(
hour:
23
,
minute:
59
),
const
TimeOfDay
(
hour:
12
,
minute:
0
),
]..
sort
(),
<
TimeOfDay
>[
const
TimeOfDay
(
hour:
0
,
minute:
0
),
const
TimeOfDay
(
hour:
12
,
minute:
0
),
const
TimeOfDay
(
hour:
23
,
minute:
59
),
]
);
});
});
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment