Skip to content
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

Fix- Upcoming events are not showing in dashboard #98

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions lib/data/core/extensions/date_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ extension DateExtention on int {
extension TimestampExtension on DateTime {
int get futureDateSelectionYear => year + 2;

bool isDateInCurrentWeek(DateTime currentDate) =>
month == currentDate.month &&
day >= currentDate.day &&
day <=
currentDate
.add(Duration(days: DateTime.daysPerWeek - currentDate.weekday))
.day;
bool isDateInCurrentWeek(DateTime currentDate) {
DateTime now = DateTime.now().dateOnly;
DateTime startOfWeek =
now.dateOnly.subtract(Duration(days: now.weekday - 1));
DateTime endOfWeek = startOfWeek.dateOnly
.add(const Duration(days: DateTime.daysPerWeek - 1));

DateTime birthdayThisYear = DateTime(currentDate.year, month, day).dateOnly;
DateTime birthdayNextYear =
DateTime(currentDate.year + 1, month, day).dateOnly;

return (birthdayThisYear.isAfterOrSame(now) &&
birthdayThisYear.isBefore(endOfWeek)) ||
(birthdayNextYear.isAfterOrSame(now) &&
birthdayNextYear.isBefore(endOfWeek));
}
Comment on lines +20 to +35
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming isDateInCurrentWeek to isBirthdayWithinCurrentWeek for better clarity, and add detailed comments explaining the logic.


int calculateDifferenceInYears(DateTime currentDate) {
int yearDifference = year - currentDate.year;
Expand All @@ -36,7 +45,7 @@ extension TimestampExtension on DateTime {
bool isBeforeOrSame(DateTime date) =>
isBefore(date) || isAtSameMomentAs(date);

bool isAfterOrSame(DateTime date) => isBefore(date) || isAtSameMomentAs(date);
bool isAfterOrSame(DateTime date) => isAfter(date) || isAtSameMomentAs(date);

int get timeStampToInt => millisecondsSinceEpoch;

Expand Down
14 changes: 12 additions & 2 deletions lib/data/core/utils/date_formatter.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter_gen/gen_l10n/app_localization.dart';
import 'package:intl/intl.dart';
import 'package:projectunity/data/core/extensions/date_time.dart';
import 'package:projectunity/data/core/extensions/string_extension.dart';
import 'package:projectunity/data/model/leave/leave.dart';

class DateFormatter {
Expand Down Expand Up @@ -86,12 +87,21 @@ class DateFormatter {
}
}

String getEventDateRepresentation(DateTime dt) {
if (today.dateOnly.isAtSameMomentAs(dt.dateOnly)) {
return _localization.dateFormatter_today.toLowerCase();
} else if (today.add(oneDay).dateOnly.isAtSameMomentAs(dt.dateOnly)) {
return _localization.dateFormatter_tomorrow.toLowerCase();
}
return _localization.date_format_MMMd(dt).capitalize();
}

String showBirthdays({required DateTime dateTime, required String name}) {
final today = DateTime.now().dateOnly;
if (dateTime.dateOnly.isAtSameMomentAs(today)) {
return _localization.present_birthday_text(name);
} else {
return "${_localization.upcoming_birthday_text(name)} ${getDateRepresentation(dateTime).toLowerCase()}!🎂🎁";
return "${_localization.upcoming_birthday_text(name)} ${getEventDateRepresentation(dateTime)}!🎂🎁";
}
}

Expand All @@ -105,7 +115,7 @@ class DateFormatter {
if (upcomingDate.isAtSameMomentAs(today)) {
return _localization.present_anniversary_text(name, yearDifference);
} else {
return "${_localization.upcoming_anniversary_text(name, yearDifference)} ${getDateRepresentation(upcomingDate).toLowerCase()}!🎉";
return "${_localization.upcoming_anniversary_text(name, yearDifference)} ${getEventDateRepresentation(upcomingDate)}!🎉";
}
}

Expand Down
12 changes: 12 additions & 0 deletions lib/data/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@
}
},


"date_format_MMMd": "{date}",
"@date_format_MMMd": {
"placeholders": {
"date": {
"type": "DateTime",
"format": "MMMMd"
}
}
},


"date_format_yMMMM": "{date}",
"@date_format_yMMMM": {
"placeholders": {
Expand Down
9 changes: 7 additions & 2 deletions lib/ui/shared/events/celebrations_event_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,18 @@ class CurrentWeekEventCard extends StatelessWidget {
),
const SizedBox(width: 10),
Expanded(
child: Text(isAnniversary
child: Text(
isAnniversary
? DateFormatter(context.l10n).showAnniversaries(
dateOfJoining: event.dateTime,
upcomingDate: event.upcomingDate,
name: event.name)
: DateFormatter(context.l10n).showBirthdays(
dateTime: event.dateTime, name: event.name))),
dateTime: event.dateTime, name: event.name),
style: AppTextStyle.style14
.copyWith(color: context.colorScheme.textPrimary),
),
),
],
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ void main() {

test('Add applied leaves on leave list test', () {
when(leaveRepo.fetchLeave(leaveId: casualLeave.leaveId))
.thenAnswer((realInvocation) async => casualLeave);
.thenAnswer((_) async => casualLeave);
bloc.add(UpdateLeave(leaveId: casualLeave.leaveId));
expectLater(
bloc.stream,
emits(UserLeaveState(
casualLeaves: [casualLeave]
.groupByMonth((element) => element.appliedOn))));
.groupByMonth((element) => element.startDate))));
});
});

Expand Down
Loading