-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display limits of email recovery #3281
Open
florentos17
wants to merge
4
commits into
master
Choose a base branch
from
Display-Limits-of-Email-Recovery
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a14a1b8
TF3219 display limits of email recovery in a yellow banner
florentos17 de6b5e4
TF-3219 suggested options for deletion date are now filtered accordin…
florentos17 bb33162
TF-3219 fixup! the session horizon is now correctly formatted and used
florentos17 140041e
TF-3219 removed package `duration` usages
florentos17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
class DurationUtils { | ||
|
||
// this class is a local copy of the one found at | ||
// https://github.com/desktop-dart/duration/blob/master/lib/src/parse/parse.dart#L6 | ||
static Duration parseDuration(String input, {String separator = ','}) { | ||
bool isNegative = false; | ||
if (input.startsWith('-')) { | ||
isNegative = true; | ||
input = input.substring(1); | ||
} else if (input.startsWith('+')) { | ||
input = input.substring(1); | ||
} | ||
|
||
final parts = input.split(separator).map((t) => t.trim()).toList(); | ||
|
||
int? weeks; | ||
int? days; | ||
int? hours; | ||
int? minutes; | ||
int? seconds; | ||
int? milliseconds; | ||
int? microseconds; | ||
|
||
for (String part in parts) { | ||
final match = RegExp(r'^(\d+)(w|d|h|min|m|s|ms|us)$').matchAsPrefix(part); | ||
if (match == null) throw const FormatException('Invalid duration format'); | ||
|
||
int value = int.parse(match.group(1)!); | ||
String? unit = match.group(2); | ||
|
||
switch (unit) { | ||
case 'w': | ||
if (weeks != null) { | ||
throw const FormatException('Weeks specified multiple times'); | ||
} | ||
weeks = value; | ||
break; | ||
case 'd': | ||
if (days != null) { | ||
throw const FormatException('Days specified multiple times'); | ||
} | ||
days = value; | ||
break; | ||
case 'h': | ||
if (hours != null) { | ||
throw const FormatException('Hours specified multiple times'); | ||
} | ||
hours = value; | ||
break; | ||
case 'min': | ||
case 'm': | ||
if (minutes != null) { | ||
throw const FormatException('Minutes specified multiple times'); | ||
} | ||
minutes = value; | ||
break; | ||
case 's': | ||
if (seconds != null) { | ||
throw const FormatException('Seconds specified multiple times'); | ||
} | ||
seconds = value; | ||
break; | ||
case 'ms': | ||
if (milliseconds != null) { | ||
throw const FormatException('Milliseconds specified multiple times'); | ||
} | ||
milliseconds = value; | ||
break; | ||
case 'us': | ||
if (microseconds != null) { | ||
throw const FormatException('Microseconds specified multiple times'); | ||
} | ||
microseconds = value; | ||
break; | ||
default: | ||
throw FormatException('Invalid duration unit $unit'); | ||
} | ||
} | ||
|
||
var ret = Duration( | ||
days: (days ?? 0) + (weeks ?? 0) * 7, | ||
hours: hours ?? 0, | ||
minutes: minutes ?? 0, | ||
seconds: seconds ?? 0, | ||
milliseconds: milliseconds ?? 0, | ||
microseconds: microseconds ?? 0); | ||
return isNegative ? -ret : ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:core/utils/duration_utils.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
|
||
group('parseDuration', () { | ||
test('duration', () { | ||
expect((DurationUtils.parseDuration('20d,10h,30m')).toString(), '490:30:00.000000'); | ||
}); | ||
|
||
test('duration weeks', () { | ||
expect((DurationUtils.parseDuration('2w,20d,10h,30m')).toString(), '826:30:00.000000'); | ||
}); | ||
test('Negative', () { | ||
expect(DurationUtils.parseDuration('-20d,10h,30m').toString(), '-490:30:00.000000'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
lib/features/email_recovery/presentation/widgets/limits_banner.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class LimitsBanner extends StatelessWidget { | ||
final String bannerContent; | ||
|
||
const LimitsBanner({ | ||
super.key, | ||
required this.bannerContent, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
width: double.infinity, | ||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0), | ||
decoration: BoxDecoration( | ||
color: Colors.yellow[400], | ||
borderRadius: BorderRadius.circular(8.0), | ||
), | ||
child: Center( | ||
child: Text( | ||
bannerContent, | ||
style: const TextStyle( | ||
fontSize: 16, | ||
color: Colors.black, | ||
fontWeight: FontWeight.bold, | ||
), | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need this? how about using dependency directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remembered it was asked by @tddang-linagora
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should minimize the using of third party library. If we only need a small function, let's copy it over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from my point of view, we should use 3rd party lib to get the support from the community, don't need effort in maintaining it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tend to agree with @hoangdat .
Why maintain this code if we have it from a healthy package (size, community, etc..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll drop the commit
removed package duration usages
when squashing then (if ok for you @tddang-linagora)