Skip to content

Commit

Permalink
[Domain] Added a model to represent the character birthday.
Browse files Browse the repository at this point in the history
Added a few date util methods
  • Loading branch information
Wolfteam committed May 6, 2022
1 parent aaf576d commit 84dc75e
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/domain/extensions/datetime_extensions.dart
@@ -0,0 +1,7 @@
extension DateTimeExtensions on DateTime {
bool isAfterInclusive(DateTime other) => compareTo(other) >= 0;

bool isBeforeInclusive(DateTime other) => compareTo(other) <= 0;

bool isBetweenInclusive(DateTime first, DateTime last) => isAfterInclusive(first) && isBeforeInclusive(last);
}
@@ -0,0 +1,15 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'character_birthday_model.freezed.dart';

@freezed
class CharacterBirthdayModel with _$CharacterBirthdayModel {
const factory CharacterBirthdayModel({
required String key,
required String name,
required String image,
required DateTime birthday,
required String birthdayString,
required int daysUntilBirthday,
}) = _CharacterBirthdayModel;
}
1 change: 1 addition & 0 deletions lib/domain/models/models.dart
Expand Up @@ -2,6 +2,7 @@ export 'artifacts/artifact_card_model.dart';
export 'banner_history/banner_history_item_model.dart';
export 'banner_history/banner_history_period_model.dart';
export 'banner_history/item_release_history_model.dart';
export 'birthdays_per_month/character_birthday_model.dart';
export 'calculator_asc_materials/ascension_materials_summary.dart';
export 'calculator_asc_materials/calculator_session_model.dart';
export 'calculator_asc_materials/character_skill.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/domain/services/genshin_service.dart
Expand Up @@ -96,4 +96,6 @@ abstract class GenshinService {
List<ChartTopItemModel> getTopCharts(ChartType type);
List<ChartBirthdayMonthModel> getCharacterBirthdaysForCharts();
List<ChartElementItemModel> getElementsForCharts();

List<CharacterBirthdayModel> getCharacterBirthdays({int? month, int? day});
}
2 changes: 1 addition & 1 deletion lib/domain/services/locale_service.dart
Expand Up @@ -8,7 +8,7 @@ abstract class LocaleService {

String getFormattedLocale(AppLanguageType language);

DateTime getCharBirthDate(String? birthday);
DateTime getCharBirthDate(String? birthday, {bool useCurrentYear = false});

String formatCharBirthDate(String? birthday);

Expand Down
2 changes: 2 additions & 0 deletions lib/domain/services/telemetry_service.dart
Expand Up @@ -69,4 +69,6 @@ abstract class TelemetryService {
Future<void> trackItemReleaseHistoryOpened(String itemKey);

Future<void> trackChartsOpened();

Future<void> trackBirthdaysPerMonthOpened(int month);
}
22 changes: 22 additions & 0 deletions lib/domain/utils/date_utils.dart
Expand Up @@ -22,4 +22,26 @@ class DateUtils {
final format = useTwentyFourHoursFormat ? twentyFourHoursFormat : defaultFormat;
return formatDate(date, format: format);
}

static int getLastDayOfMonth(int month) {
final now = DateTime.now();
return DateTime(now.year, month + 1, 0).day;
}

static String getMonthFullName(int month) {
final formatter = DateFormat('MMMM');
final formatted = formatter.format(DateTime(DateTime.now().year, month));
//languages like spanish need the first letter in upper case
return toBeginningOfSentenceCase(formatted)!;
}

static List<String> getAllMonthsName({String format = 'MMM'}) {
final now = DateTime.now();
final formatter = DateFormat(format);
return List.generate(DateTime.monthsPerYear, (int index) {
final date = DateTime(now.year, index + 1);
final formatted = formatter.format(date);
return toBeginningOfSentenceCase(formatted)!;
});
}
}

0 comments on commit 84dc75e

Please sign in to comment.