@@ -18,7 +18,7 @@ import Foundation
1818
1919/// A model type representing the current user's birthday.
2020struct Birthday : Decodable {
21- let integerDate : Birthday . IntegerDate
21+ fileprivate let integerDate : Birthday . IntegerDate
2222
2323 /// The birthday as a `Date`.
2424 var date : Date ? {
@@ -30,7 +30,7 @@ struct Birthday: Decodable {
3030 year: currentYear. year,
3131 month: integerDate. month,
3232 day: integerDate. day)
33- guard let d = comps. date else { return nil }
33+ guard let d = comps. date, comps . isValidDate else { return nil }
3434 if d < now {
3535 var nextYearComponent = DateComponents ( )
3636 nextYearComponent. year = 1
@@ -39,12 +39,20 @@ struct Birthday: Decodable {
3939 } else {
4040 return d
4141 }
42- }
42+ }
4343
4444 init ( from decoder: Decoder ) throws {
4545 let container = try decoder. container ( keyedBy: CodingKeys . self)
4646 self . integerDate = try container. decode ( IntegerDate . self, forKey: . integerDate)
4747 }
48+
49+ init ( integerDate: IntegerDate ) {
50+ self . integerDate = integerDate
51+ }
52+
53+ static var noBirthday : Birthday ? {
54+ return Birthday ( integerDate: IntegerDate ( month: . min, day: . min) )
55+ }
4856}
4957
5058extension Birthday {
@@ -64,7 +72,7 @@ extension Birthday {
6472extension Birthday : CustomStringConvertible {
6573 /// Converts the instances `date` to a `String`.
6674 var description : String {
67- return date? . description ?? " NA "
75+ return date? . description ?? " No birthday "
6876 }
6977}
7078
0 commit comments