Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
onTime
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
onTime InnoLab
onTime
Commits
1a208873
Commit
1a208873
authored
1 year ago
by
doodlezucc
Browse files
Options
Downloads
Patches
Plain Diff
improve start of week calculation
parent
429bd8af
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/util/date_extension.dart
+2
-1
2 additions, 1 deletion
lib/util/date_extension.dart
test/start_of_week_test.dart
+33
-0
33 additions, 0 deletions
test/start_of_week_test.dart
with
35 additions
and
1 deletion
lib/util/date_extension.dart
+
2
−
1
View file @
1a208873
...
...
@@ -24,6 +24,7 @@ extension DateExtension on DateTime {
}
DateTime
atStartOfWeek
()
{
return
subtract
(
Duration
(
days:
weekday
-
1
));
final
date
=
subtract
(
Duration
(
days:
weekday
-
1
));
return
DateTime
(
date
.
year
,
date
.
month
,
date
.
day
);
}
}
This diff is collapsed.
Click to expand it.
test/start_of_week_test.dart
0 → 100644
+
33
−
0
View file @
1a208873
import
'package:better_untis/util/date_extension.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
()
{
final
startOfMonday
=
DateTime
(
2023
,
3
,
20
,
0
,
0
);
test
(
'Start of week at start of monday'
,
()
{
final
startOfWeek
=
startOfMonday
.
atStartOfWeek
();
expect
(
startOfWeek
,
startOfMonday
);
});
test
(
'Start of week at end of tuesday'
,
()
{
final
endOfTuesday
=
DateTime
(
2023
,
3
,
21
,
23
,
59
);
final
startOfWeek
=
endOfTuesday
.
atStartOfWeek
();
expect
(
startOfWeek
,
startOfMonday
);
});
test
(
'Start of week at end of sunday'
,
()
{
final
endOfSaturday
=
DateTime
(
2023
,
3
,
26
,
23
,
59
);
final
startOfWeek
=
endOfSaturday
.
atStartOfWeek
();
expect
(
startOfWeek
,
startOfMonday
);
});
test
(
'Start of week at end of next monday'
,
()
{
final
startOfNextMonday
=
DateTime
(
2023
,
3
,
27
,
0
,
0
);
final
startOfWeek
=
startOfNextMonday
.
atStartOfWeek
();
expect
(
startOfWeek
,
startOfNextMonday
);
});
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment