-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Dates Screen Stylistic Changes #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b02e13b
1899706
c5967f6
0656c15
77f5b89
070c1ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "edit_square.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "certificate_icon.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "locked.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "school.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,18 @@ import Foundation | |
|
||
public extension Date { | ||
init(iso8601: String) { | ||
let date: Date | ||
let formats = ["yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ"] | ||
var date: Date | ||
var dateFormatter: DateFormatter? | ||
dateFormatter = DateFormatter() | ||
dateFormatter?.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" | ||
dateFormatter?.locale = Locale(identifier: "en_US_POSIX") | ||
date = dateFormatter?.date(from: iso8601) ?? Date() | ||
|
||
date = formats.compactMap { format in | ||
dateFormatter?.dateFormat = format | ||
return dateFormatter?.date(from: iso8601) | ||
} | ||
.first ?? Date() | ||
|
||
defer { | ||
dateFormatter = nil | ||
} | ||
|
@@ -104,7 +110,7 @@ public extension Date { | |
case .iso8601: | ||
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" | ||
case .shortWeekdayMonthDayYear: | ||
dateFormatter.dateFormat = "EEE, MMM d, yyyy" | ||
applyDateFormatterForShortWeekdayMonthDayYear(dateFormatter: dateFormatter) | ||
} | ||
|
||
let date = dateFormatter.string(from: self) | ||
|
@@ -134,7 +140,56 @@ public extension Date { | |
case .iso8601: | ||
return date | ||
case .shortWeekdayMonthDayYear: | ||
return date | ||
return getShortWeekdayMonthDayYear(dateFormatterString: date) | ||
} | ||
} | ||
|
||
private func applyDateFormatterForShortWeekdayMonthDayYear(dateFormatter: DateFormatter) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
if isCurrentYear() { | ||
let days = Calendar.current.dateComponents([.day], from: self, to: Date()) | ||
if let day = days.day, (-6 ... -2).contains(day) { | ||
dateFormatter.dateFormat = "EEEE" | ||
} else { | ||
dateFormatter.dateFormat = "MMMM d" | ||
} | ||
} else { | ||
dateFormatter.dateFormat = "MMMM d, yyyy" | ||
} | ||
} | ||
|
||
private func getShortWeekdayMonthDayYear(dateFormatterString: String) -> String { | ||
let days = Calendar.current.dateComponents([.day], from: self, to: Date()) | ||
|
||
if let day = days.day { | ||
guard isCurrentYear() else { | ||
// It's past year or future year | ||
return dateFormatterString | ||
} | ||
|
||
switch day { | ||
case -6...(-2): | ||
return dateFormatterString | ||
case 2...6: | ||
return self.timeAgoDisplay() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
case -1: | ||
return CoreLocalization.CourseDates.tomorrow | ||
case 1: | ||
return CoreLocalization.CourseDates.yesterday | ||
default: | ||
if day > 6 || day < -6 { | ||
return dateFormatterString | ||
} else { | ||
// It means, date is in hours past due or upcoming | ||
return self.timeAgoDisplay() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
} | ||
} | ||
} else { | ||
return dateFormatterString | ||
} | ||
} | ||
|
||
func isCurrentYear() -> Bool { | ||
let years = Calendar.current.dateComponents([.year], from: self, to: Date()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed it to components as it seems more appropriate. |
||
return years.year == 0 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about renaming the Date to
CourseDates
for clarity?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done