Skip to content

Commit

Permalink
Extract toImfFixDateString() extension method
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej-Hlatky committed Mar 22, 2024
1 parent 34a1957 commit 35c32b9
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/src/autogram_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export 'iautogram_service.dart';

/// Implements [IAutogramService] using [Autogram] instance.
class AutogramService implements IAutogramService {
static final _rfcDateFormat =
DateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", 'en_US');

final Autogram _autogram;

AutogramService({
Expand Down Expand Up @@ -85,12 +82,20 @@ class AutogramService implements IAutogramService {
return _autogram
.documentsGuidGet(
guid: documentId,
ifModifiedSince: ifModifiedSince != null
// TODO Extract as extension fun with reasonable name
// https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.1
? _rfcDateFormat.format(ifModifiedSince.toUtc())
: null,
ifModifiedSince: ifModifiedSince?.toImfFixDateString(),
)
.then(unwrap);
}
}

extension _DateTimeExtensions on DateTime {
static final _imfFixDateFormat =
DateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", 'en_US');

/// Returns this date formatted as "IMF-fixdate".
///
/// See: <https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.1>
String toImfFixDateString() {
return _imfFixDateFormat.format(toUtc());
}
}

0 comments on commit 35c32b9

Please sign in to comment.