Skip to content

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Core/Core/Assets.xcassets/Date/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

15 changes: 15 additions & 0 deletions Core/Core/Assets.xcassets/Date/assignment.imageset/Contents.json
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"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Core/Core/Assets.xcassets/Date/locked.imageset/Contents.json
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"
}
}
4 changes: 4 additions & 0 deletions Core/Core/Assets.xcassets/Date/locked.imageset/locked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Core/Core/Assets.xcassets/Date/school.imageset/Contents.json
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"
}
}
3 changes: 3 additions & 0 deletions Core/Core/Assets.xcassets/Date/school.imageset/school.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 60 additions & 5 deletions Core/Core/Extensions/DateExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -134,7 +140,56 @@ public extension Date {
case .iso8601:
return date
case .shortWeekdayMonthDayYear:
return date
return getShortWeekdayMonthDayYear(dateFormatterString: date)
}
}

private func applyDateFormatterForShortWeekdayMonthDayYear(dateFormatter: DateFormatter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming it to applyShortWeekdayMonthDayYear as dateFormatter is a parameter so I guess there isn't any need to mention it in the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming years to datecomponents or to components?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
}
4 changes: 4 additions & 0 deletions Core/Core/SwiftGen/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public enum CoreAssets {
public static let docCircle = ImageAsset(name: "doc.circle")
public static let videoCircle = ImageAsset(name: "video.circle")
public static let dashboardEmptyPage = ImageAsset(name: "DashboardEmptyPage")
public static let assignment = ImageAsset(name: "assignment")
public static let certificateIcon = ImageAsset(name: "certificateIcon")
public static let locked = ImageAsset(name: "locked")
public static let school = ImageAsset(name: "school")
public static let addComment = ImageAsset(name: "addComment")
public static let allPosts = ImageAsset(name: "allPosts")
public static let chapter = ImageAsset(name: "chapter")
Expand Down
6 changes: 6 additions & 0 deletions Core/Core/SwiftGen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@ public enum CoreLocalization {
public static let completed = CoreLocalization.tr("Localizable", "COURSE_DATES.COMPLETED", fallback: "Completed")
/// Due next
public static let dueNext = CoreLocalization.tr("Localizable", "COURSE_DATES.DUE_NEXT", fallback: "Due next")
/// Items Hidden
public static let itemsHidden = CoreLocalization.tr("Localizable", "COURSE_DATES.ITEMS_HIDDEN", fallback: "Items Hidden")
/// Past due
public static let pastDue = CoreLocalization.tr("Localizable", "COURSE_DATES.PAST_DUE", fallback: "Past due")
/// Today
public static let today = CoreLocalization.tr("Localizable", "COURSE_DATES.TODAY", fallback: "Today")
/// Tomorrow
public static let tomorrow = CoreLocalization.tr("Localizable", "COURSE_DATES.TOMORROW", fallback: "Tomorrow")
/// Unreleased
public static let unreleased = CoreLocalization.tr("Localizable", "COURSE_DATES.UNRELEASED", fallback: "Unreleased")
/// Verified Only
public static let verifiedOnly = CoreLocalization.tr("Localizable", "COURSE_DATES.VERIFIED_ONLY", fallback: "Verified Only")
/// Yesterday
public static let yesterday = CoreLocalization.tr("Localizable", "COURSE_DATES.YESTERDAY", fallback: "Yesterday")
}
public enum Date {
/// Ended
Expand Down
3 changes: 3 additions & 0 deletions Core/Core/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
"COURSE_DATES.DUE_NEXT" = "Due next";
"COURSE_DATES.UNRELEASED" = "Unreleased";
"COURSE_DATES.VERIFIED_ONLY" = "Verified Only";
"COURSE_DATES.TOMORROW" = "Tomorrow";
"COURSE_DATES.YESTERDAY" = "Yesterday";
"COURSE_DATES.ITEMS_HIDDEN" = "Items Hidden";

"SOCIAL_SIGN_CANCELED" = "The user canceled the sign-in flow.";

Expand Down
3 changes: 3 additions & 0 deletions Core/Core/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
"COURSE_DATES.DUE_NEXT" = "Due next";
"COURSE_DATES.UNRELEASED" = "Unreleased";
"COURSE_DATES.VERIFIED_ONLY" = "Verified Only";
"COURSE_DATES.TOMORROW" = "Tomorrow";
"COURSE_DATES.YESTERDAY" = "Yesterday";
"COURSE_DATES.ITEMS_HIDDEN" = "Items Hidden";

"SOCIAL_SIGN_CANCELED" = "The user canceled the sign-in flow.";
"AUTHORIZATION_FAILED" = "Authorization failed.";
Expand Down
Loading