mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 03:19:11 +08:00
Avoid recreating DateFormats
They only need to be created once. This should result in a minor performance gain while building the folder views.
This commit is contained in:
@ -14,6 +14,9 @@ class JournalView extends StatelessWidget {
|
|||||||
final NotesFolder folder;
|
final NotesFolder folder;
|
||||||
final String emptyText;
|
final String emptyText;
|
||||||
|
|
||||||
|
static final _dateFormat = DateFormat('dd MMM, yyyy ');
|
||||||
|
static final _timeFormat = DateFormat('Hm');
|
||||||
|
|
||||||
JournalView({
|
JournalView({
|
||||||
@required this.folder,
|
@required this.folder,
|
||||||
@required this.noteSelectedFunction,
|
@required this.noteSelectedFunction,
|
||||||
@ -41,11 +44,8 @@ class JournalView extends StatelessWidget {
|
|||||||
date = note.created;
|
date = note.created;
|
||||||
}
|
}
|
||||||
if (date != null) {
|
if (date != null) {
|
||||||
var formatter = DateFormat('dd MMM, yyyy ');
|
var dateStr = _dateFormat.format(date);
|
||||||
var dateStr = formatter.format(date);
|
var time = _timeFormat.format(date);
|
||||||
|
|
||||||
var timeFormatter = DateFormat('Hm');
|
|
||||||
var time = timeFormatter.format(date);
|
|
||||||
|
|
||||||
var timeColor = textTheme.body1.color.withAlpha(100);
|
var timeColor = textTheme.body1.color.withAlpha(100);
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ class StandardView extends StatelessWidget {
|
|||||||
final StandardViewHeader headerType;
|
final StandardViewHeader headerType;
|
||||||
final bool showSummary;
|
final bool showSummary;
|
||||||
|
|
||||||
|
static final _dateFormat = DateFormat('dd MMM, yyyy');
|
||||||
|
|
||||||
StandardView({
|
StandardView({
|
||||||
@required this.folder,
|
@required this.folder,
|
||||||
@required this.noteSelectedFunction,
|
@required this.noteSelectedFunction,
|
||||||
@ -80,8 +82,7 @@ class StandardView extends StatelessWidget {
|
|||||||
date = note.created;
|
date = note.created;
|
||||||
}
|
}
|
||||||
if (date != null) {
|
if (date != null) {
|
||||||
var formatter = DateFormat('dd MMM, yyyy');
|
var dateStr = _dateFormat.format(date);
|
||||||
var dateStr = formatter.format(date);
|
|
||||||
trailing = Text(dateStr, style: textTheme.caption);
|
trailing = Text(dateStr, style: textTheme.caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
final _simpleDateFormat = DateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||||
|
final _iso8601DateFormat = DateFormat("yyyy-MM-ddTHH:mm:ss");
|
||||||
|
|
||||||
String toSimpleDateTime(DateTime dt) {
|
String toSimpleDateTime(DateTime dt) {
|
||||||
return DateFormat("yyyy-MM-dd-HH-mm-ss").format(dt);
|
return _simpleDateFormat.format(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
String toIso8601(DateTime dt) {
|
String toIso8601(DateTime dt) {
|
||||||
return DateFormat("yyyy-MM-ddTHH:mm:ss").format(dt);
|
return _iso8601DateFormat.format(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
String toIso8601WithTimezone(DateTime dt, [Duration offset]) {
|
String toIso8601WithTimezone(DateTime dt, [Duration offset]) {
|
||||||
var result = DateFormat("yyyy-MM-ddTHH:mm:ss").format(dt);
|
var result = _iso8601DateFormat.format(dt);
|
||||||
|
|
||||||
offset = offset ?? dt.timeZoneOffset;
|
offset = offset ?? dt.timeZoneOffset;
|
||||||
int minutes = (offset.inMinutes % 60);
|
int minutes = (offset.inMinutes % 60);
|
||||||
|
Reference in New Issue
Block a user