2023-10-02 07:12:24 +00:00
|
|
|
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
|
|
|
import 'package:appflowy_backend/protobuf/flowy-date/entities.pb.dart';
|
|
|
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
2024-02-24 13:54:10 +00:00
|
|
|
import 'package:appflowy_result/appflowy_result.dart';
|
2023-10-02 07:12:24 +00:00
|
|
|
|
|
|
|
class DateService {
|
2024-02-24 13:54:10 +00:00
|
|
|
static Future<FlowyResult<DateTime, FlowyError>> queryDate(
|
|
|
|
String search,
|
|
|
|
) async {
|
2023-10-02 07:12:24 +00:00
|
|
|
final query = DateQueryPB.create()..query = search;
|
2024-02-24 13:54:10 +00:00
|
|
|
final result = await DateEventQueryDate(query).send();
|
|
|
|
return result.fold(
|
|
|
|
(s) {
|
|
|
|
final date = DateTime.tryParse(s.date);
|
|
|
|
if (date != null) {
|
|
|
|
return FlowyResult.success(date);
|
|
|
|
}
|
|
|
|
return FlowyResult.failure(
|
|
|
|
FlowyError(msg: 'Could not parse Date (NLP) from String'),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
(e) => FlowyResult.failure(e),
|
|
|
|
);
|
2023-10-02 07:12:24 +00:00
|
|
|
}
|
|
|
|
}
|