From 44c91a68ec4879c74a598a492ce59a510ca18ae2 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 11 Jan 2021 01:35:41 +0100 Subject: [PATCH] Improve how time of birth is handled --- Motivation/AgeView.swift | 12 ++++- Motivation/Configuration.xib | 5 ++- Motivation/ConfigureSheetController.swift | 55 +++++++++++++++++++---- Motivation/Preferences.swift | 45 +++++++++++-------- 4 files changed, 87 insertions(+), 30 deletions(-) diff --git a/Motivation/AgeView.swift b/Motivation/AgeView.swift index 414329c..00a92d2 100644 --- a/Motivation/AgeView.swift +++ b/Motivation/AgeView.swift @@ -115,7 +115,7 @@ class AgeView: ScreenSaverView { animationTimeInterval = 1 / 30 // Recall preferences - birthday = Preferences().birthday + updateBirthday() // Setup the label addSubview(textLabel) @@ -165,9 +165,17 @@ class AgeView: ScreenSaverView { /// Birthday changed @objc private func birthdayDidChange(_ notification: Notification?) { - birthday = Preferences().birthday + updateBirthday() } + private func updateBirthday() { + if let dateComponents = Preferences().birthdayComponents { + birthday = Calendar.current.date(from: dateComponents) + } else { + birthday = Date() + } + } + /// Update the font for the current size private func updateFont() { if birthday != nil { diff --git a/Motivation/Configuration.xib b/Motivation/Configuration.xib index 676e59a..55aca8f 100644 --- a/Motivation/Configuration.xib +++ b/Motivation/Configuration.xib @@ -9,6 +9,7 @@ + @@ -105,8 +106,8 @@ DQ