Soru/moor
This commit is contained in:
parent
79a306351e
commit
f594c7005d
55 changed files with 1034 additions and 1133 deletions
|
|
@ -3,20 +3,20 @@ import 'package:flutter/material.dart';
|
|||
|
||||
/// Provides extra functionality for formatting the time.
|
||||
extension DateTimeExtension on DateTime {
|
||||
operator <(DateTime other) {
|
||||
return this.millisecondsSinceEpoch < other.millisecondsSinceEpoch;
|
||||
bool operator <(DateTime other) {
|
||||
return millisecondsSinceEpoch < other.millisecondsSinceEpoch;
|
||||
}
|
||||
|
||||
operator >(DateTime other) {
|
||||
return this.millisecondsSinceEpoch > other.millisecondsSinceEpoch;
|
||||
bool operator >(DateTime other) {
|
||||
return millisecondsSinceEpoch > other.millisecondsSinceEpoch;
|
||||
}
|
||||
|
||||
operator >=(DateTime other) {
|
||||
return this.millisecondsSinceEpoch >= other.millisecondsSinceEpoch;
|
||||
bool operator >=(DateTime other) {
|
||||
return millisecondsSinceEpoch >= other.millisecondsSinceEpoch;
|
||||
}
|
||||
|
||||
operator <=(DateTime other) {
|
||||
return this.millisecondsSinceEpoch <= other.millisecondsSinceEpoch;
|
||||
bool operator <=(DateTime other) {
|
||||
return millisecondsSinceEpoch <= other.millisecondsSinceEpoch;
|
||||
}
|
||||
|
||||
/// Two message events can belong to the same environment. That means that they
|
||||
|
|
@ -34,28 +34,28 @@ extension DateTimeExtension on DateTime {
|
|||
/// Returns a simple time String.
|
||||
/// TODO: Add localization
|
||||
String localizedTimeOfDay(BuildContext context) {
|
||||
return L10n.of(context).timeOfDay(_z(this.hour % 12), _z(this.hour),
|
||||
_z(this.minute), this.hour > 11 ? 'pm' : 'am');
|
||||
return L10n.of(context).timeOfDay(
|
||||
_z(hour % 12), _z(hour), _z(minute), hour > 11 ? 'pm' : 'am');
|
||||
}
|
||||
|
||||
/// Returns [localizedTimeOfDay()] if the ChatTime is today, the name of the week
|
||||
/// day if the ChatTime is this week and a date string else.
|
||||
String localizedTimeShort(BuildContext context) {
|
||||
DateTime now = DateTime.now();
|
||||
var now = DateTime.now();
|
||||
|
||||
bool sameYear = now.year == this.year;
|
||||
var sameYear = now.year == year;
|
||||
|
||||
bool sameDay = sameYear && now.month == this.month && now.day == this.day;
|
||||
var sameDay = sameYear && now.month == month && now.day == day;
|
||||
|
||||
bool sameWeek = sameYear &&
|
||||
var sameWeek = sameYear &&
|
||||
!sameDay &&
|
||||
now.millisecondsSinceEpoch - this.millisecondsSinceEpoch <
|
||||
now.millisecondsSinceEpoch - millisecondsSinceEpoch <
|
||||
1000 * 60 * 60 * 24 * 7;
|
||||
|
||||
if (sameDay) {
|
||||
return localizedTimeOfDay(context);
|
||||
} else if (sameWeek) {
|
||||
switch (this.weekday) {
|
||||
switch (weekday) {
|
||||
case 1:
|
||||
return L10n.of(context).monday;
|
||||
case 2:
|
||||
|
|
@ -73,29 +73,26 @@ extension DateTimeExtension on DateTime {
|
|||
}
|
||||
} else if (sameYear) {
|
||||
return L10n.of(context).dateWithoutYear(
|
||||
this.month.toString().padLeft(2, '0'),
|
||||
this.day.toString().padLeft(2, '0'));
|
||||
month.toString().padLeft(2, '0'), day.toString().padLeft(2, '0'));
|
||||
}
|
||||
return L10n.of(context).dateWithYear(
|
||||
this.year.toString(),
|
||||
this.month.toString().padLeft(2, '0'),
|
||||
this.day.toString().padLeft(2, '0'));
|
||||
return L10n.of(context).dateWithYear(year.toString(),
|
||||
month.toString().padLeft(2, '0'), day.toString().padLeft(2, '0'));
|
||||
}
|
||||
|
||||
/// If the DateTime is today, this returns [localizedTimeOfDay()], if not it also
|
||||
/// shows the date.
|
||||
/// TODO: Add localization
|
||||
String localizedTime(BuildContext context) {
|
||||
DateTime now = DateTime.now();
|
||||
var now = DateTime.now();
|
||||
|
||||
bool sameYear = now.year == this.year;
|
||||
var sameYear = now.year == year;
|
||||
|
||||
bool sameDay = sameYear && now.month == this.month && now.day == this.day;
|
||||
var sameDay = sameYear && now.month == month && now.day == day;
|
||||
|
||||
if (sameDay) return localizedTimeOfDay(context);
|
||||
return L10n.of(context).dateAndTimeOfDay(
|
||||
localizedTimeShort(context), localizedTimeOfDay(context));
|
||||
}
|
||||
|
||||
static String _z(int i) => i < 10 ? "0${i.toString()}" : i.toString();
|
||||
static String _z(int i) => i < 10 ? '0${i.toString()}' : i.toString();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue