|
@@ -1,21 +1,21 @@
|
|
|
class ICalendar {
|
|
class ICalendar {
|
|
|
final List<ICalendarEvent> _events = [];
|
|
final List<ICalendarEvent> _events = [];
|
|
|
|
|
|
|
|
- void addEvent({
|
|
|
|
|
- required String summary,
|
|
|
|
|
- required String description,
|
|
|
|
|
- required DateTime startTime,
|
|
|
|
|
- required DateTime endTime,
|
|
|
|
|
- required List<dynamic> attendees,
|
|
|
|
|
- }) {
|
|
|
|
|
|
|
+ void addEvent(
|
|
|
|
|
+ {required String summary,
|
|
|
|
|
+ required String description,
|
|
|
|
|
+ required DateTime startTime,
|
|
|
|
|
+ required DateTime endTime,
|
|
|
|
|
+ required List<dynamic> attendees,
|
|
|
|
|
+ bool allday = false}) {
|
|
|
_events.add(
|
|
_events.add(
|
|
|
ICalendarEvent(
|
|
ICalendarEvent(
|
|
|
- summary: summary,
|
|
|
|
|
- description: description,
|
|
|
|
|
- startTime: startTime,
|
|
|
|
|
- endTime: endTime,
|
|
|
|
|
- attendees: attendees,
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+ summary: summary,
|
|
|
|
|
+ description: description,
|
|
|
|
|
+ startTime: startTime,
|
|
|
|
|
+ endTime: endTime,
|
|
|
|
|
+ attendees: attendees,
|
|
|
|
|
+ allday: allday),
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -31,8 +31,10 @@ class ICalendar {
|
|
|
buffer.writeln(
|
|
buffer.writeln(
|
|
|
'UID:${DateTime.now().millisecondsSinceEpoch}-${event.hashCode}');
|
|
'UID:${DateTime.now().millisecondsSinceEpoch}-${event.hashCode}');
|
|
|
buffer.writeln('DTSTAMP:${_formatDateTime(dtstamp)}');
|
|
buffer.writeln('DTSTAMP:${_formatDateTime(dtstamp)}');
|
|
|
- buffer.writeln('DTSTART:${_formatDateTime(event.startTime)}');
|
|
|
|
|
- buffer.writeln('DTEND:${_formatDateTime(event.endTime)}');
|
|
|
|
|
|
|
+ buffer.writeln(
|
|
|
|
|
+ 'DTSTART:${event.allday ? _formatDate(event.startTime) : _formatDateTime(event.startTime)}');
|
|
|
|
|
+ buffer.writeln(
|
|
|
|
|
+ 'DTEND:${event.allday ? _formatDate(event.startTime.add(Duration(days: 1))) : _formatDateTime(event.endTime)}');
|
|
|
buffer.writeln('SUMMARY:${event.summary}');
|
|
buffer.writeln('SUMMARY:${event.summary}');
|
|
|
buffer.writeln('DESCRIPTION:${event.description}');
|
|
buffer.writeln('DESCRIPTION:${event.description}');
|
|
|
|
|
|
|
@@ -51,6 +53,16 @@ class ICalendar {
|
|
|
String _formatDateTime(DateTime dt) {
|
|
String _formatDateTime(DateTime dt) {
|
|
|
return '${dt.toUtc().toString().replaceAll('-', '').replaceAll(':', '').replaceAll(' ', 'T').split('.')[0]}Z';
|
|
return '${dt.toUtc().toString().replaceAll('-', '').replaceAll(':', '').replaceAll(' ', 'T').split('.')[0]}Z';
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ String _formatDate(DateTime dateTime) {
|
|
|
|
|
+ // Extract year, month, and day from the DateTime object
|
|
|
|
|
+ String year = dateTime.year.toString().padLeft(4, '0');
|
|
|
|
|
+ String month = dateTime.month.toString().padLeft(2, '0');
|
|
|
|
|
+ String day = dateTime.day.toString().padLeft(2, '0');
|
|
|
|
|
+
|
|
|
|
|
+ // Combine into the YYYYMMDD format
|
|
|
|
|
+ return '$year$month$day';
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class ICalendarEvent {
|
|
class ICalendarEvent {
|
|
@@ -59,6 +71,7 @@ class ICalendarEvent {
|
|
|
final DateTime startTime;
|
|
final DateTime startTime;
|
|
|
final DateTime endTime;
|
|
final DateTime endTime;
|
|
|
final List<dynamic> attendees;
|
|
final List<dynamic> attendees;
|
|
|
|
|
+ final bool allday;
|
|
|
|
|
|
|
|
ICalendarEvent({
|
|
ICalendarEvent({
|
|
|
required this.summary,
|
|
required this.summary,
|
|
@@ -66,5 +79,6 @@ class ICalendarEvent {
|
|
|
required this.startTime,
|
|
required this.startTime,
|
|
|
required this.endTime,
|
|
required this.endTime,
|
|
|
required this.attendees,
|
|
required this.attendees,
|
|
|
|
|
+ this.allday = false,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|