Skip to content

Commit

Permalink
fix the event calender bug (#2352)
Browse files Browse the repository at this point in the history
* fix the event calender bug

* fix failing test case

* fix failing test case

* used on clause

* added test for missing line

* added test for missing line

* fix failinf test
  • Loading branch information
AVtheking authored Jan 29, 2024
1 parent 58b6e4d commit d46880b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/views/after_auth_screens/events/event_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,10 @@ _AppointmentDataSource _getCalendarDataSource(List<Event> eventsList) {
eventsList.forEach((event) {
final startDate = DateFormat('yMd').parse(event.startDate!);
print("${event.startTime!}##############################");
final startTime =
DateFormat('Hms', 'en_US').parse(event.startTime ?? '14:23:01');
final startTime = parseTime(event.startTime ?? '14:23:01');
// .parse(event.startTime!);
final endDate = DateFormat('yMd').parse(event.endDate!);
final endTime =
DateFormat('Hms', 'en_US').parse(event.endTime ?? '14:23:01');
final endTime = parseTime(event.endTime ?? '21:23:01');

// adding appointments on the calender for event[index] date time.
appointments.add(
Expand All @@ -156,6 +154,27 @@ _AppointmentDataSource _getCalendarDataSource(List<Event> eventsList) {
return _AppointmentDataSource(appointments);
}

/// a_line_ending_with_end_punctuation.
///
/// **params**:
/// * `time`: define_the_param
///
/// **returns**:
/// * `DateTime`: define_the_return
DateTime parseTime(String time) {
try {
return DateFormat('h:mm a', 'en_US').parse(time);
} on FormatException {
print('Caught FormatException: $time');
try {
return DateFormat('Hms').parse(time);
} catch (e) {
print('Caught error: $e');
throw Exception('Invalid time format: $time');
}
}
}

/// class for handling the data source.
///
/// assign the appointments value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/intl.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/events/event_model.dart';
import 'package:talawa/views/after_auth_screens/events/event_calendar.dart';
Expand All @@ -28,6 +29,27 @@ void main() {
setUp(() {
registerServices();
});
group("Test for _parseTime function", () {
test("Test parsing valid time string", () {
const timeString = "5:30 PM";
final parsedTime = parseTime(timeString);
final expectedTime = DateFormat("h:mm a").parse(timeString);
expect(parsedTime, expectedTime);
});
test("Test for invalid time string", () {
const timeString = "invalid String ";

expect(() => parseTime(timeString), throwsException);
});
test("Test parsing string in hms format", () {
const timeString = "12:12:12";

final parsedTime = parseTime(timeString);
final expectTime = DateFormat('Hms').parse(timeString);

expect(expectTime, parsedTime);
});
});
group('Tests for EventCalendar', () {
testWidgets('Testing if EventCalendar shows up', (tester) async {
await tester.pumpWidget(createEventCalendar());
Expand Down

0 comments on commit d46880b

Please sign in to comment.