Skip to content
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

feat: Dates Screen Stylistic Changes #253

Merged
Show file tree
Hide file tree
Changes from 4 commits
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/CourseDates/Contents.json
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"
}
}
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" : "calender_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.
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "lock_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.
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"
}
}
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" : "school.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.
70 changes: 63 additions & 7 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 All @@ -26,7 +32,7 @@ public extension Date {
formatter.locale = .current
formatter.unitsStyle = .full
formatter.locale = Locale(identifier: "en_US_POSIX")
if self.description == Date().description {
if description == Date().description {
return CoreLocalization.Date.justNow
} else {
return formatter.localizedString(for: self, relativeTo: Date())
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"
applyShortWeekdayMonthDayYear(dateFormatter: dateFormatter)
}

let date = dateFormatter.string(from: self)
Expand All @@ -124,7 +130,7 @@ public extension Date {
let days = Calendar.current.dateComponents([.day], from: self, to: Date())
if let day = days.day {
if day < 2 {
return self.timeAgoDisplay()
return timeAgoDisplay()
} else {
return date
}
Expand All @@ -134,7 +140,57 @@ public extension Date {
case .iso8601:
return date
case .shortWeekdayMonthDayYear:
return date
return getShortWeekdayMonthDayYear(dateFormatterString: date)
}
}

private func applyShortWeekdayMonthDayYear(dateFormatter: DateFormatter) {
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 timeAgoDisplay()
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 timeAgoDisplay()
}
}
} else {
return dateFormatterString
}
}

func isCurrentYear() -> Bool {
let selfYear = Calendar.current.component(.year, from: self)
let runningYear = Calendar.current.component(.year, from: Date())
return selfYear == runningYear
}
}
6 changes: 6 additions & 0 deletions Core/Core/SwiftGen/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public enum CoreAssets {
public static let facebookButtonColor = ColorAsset(name: "FacebookButtonColor")
public static let googleButtonColor = ColorAsset(name: "GoogleButtonColor")
public static let microsoftButtonColor = ColorAsset(name: "MicrosoftButtonColor")
public static let assignmentIcon = ImageAsset(name: "assignment_icon")
public static let calendarIcon = ImageAsset(name: "calendar_icon")
public static let certificateIcon = ImageAsset(name: "certificate_icon")
public static let lockIcon = ImageAsset(name: "lock_icon")
public static let lockWithWatchIcon = ImageAsset(name: "lock_with_watch_icon")
public static let schoolCapIcon = ImageAsset(name: "school_cap_icon")
public static let bookCircle = ImageAsset(name: "book.circle")
public static let bubbleLeftCircle = ImageAsset(name: "bubble.left.circle")
public static let docCircle = ImageAsset(name: "doc.circle")
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
Loading