-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from qwite/develop
DateFormatter + CreateAd module changes
- Loading branch information
Showing
20 changed files
with
217 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
store-platform-mvp/Extensions/DateFormatter + Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import UIKit | ||
|
||
extension DateFormatter { | ||
static let fullDateMedium: DateFormatter = { | ||
let df = DateFormatter() | ||
df.dateStyle = .medium | ||
df.timeStyle = .medium | ||
df.timeZone = .current | ||
df.locale = Locale(identifier: "en_GB") | ||
|
||
return df | ||
}() | ||
|
||
static let monthMedium: DateFormatter = { | ||
let df = DateFormatter() | ||
df.dateStyle = .medium | ||
df.timeStyle = .medium | ||
df.timeZone = .current | ||
df.locale = Locale(identifier: "en_GB") | ||
df.dateFormat = "MMM" | ||
|
||
return df | ||
}() | ||
|
||
static let dayMedium: DateFormatter = { | ||
let df = DateFormatter() | ||
df.dateStyle = .medium | ||
df.timeStyle = .medium | ||
df.timeZone = .current | ||
df.locale = Locale(identifier: "en_GB") | ||
df.dateFormat = "d" | ||
|
||
return df | ||
}() | ||
|
||
static let dayWithMonth: DateFormatter = { | ||
let df = DateFormatter() | ||
df.locale = .current | ||
df.dateFormat = "d MMM" | ||
|
||
return df | ||
}() | ||
|
||
static let time: DateFormatter = { | ||
let df = DateFormatter() | ||
df.locale = .current | ||
df.dateFormat = "HH:mm" | ||
|
||
return df | ||
}() | ||
|
||
static func getMonth(from date: Date = Date()) -> String { | ||
return DateFormatter.monthMedium.string(from: date) | ||
} | ||
|
||
static func getDayWithMonth(from date: Date = Date()) -> String { | ||
return DateFormatter.dayWithMonth.string(from: date) | ||
} | ||
|
||
static func getDayWithMonth(from date: String) -> String? { | ||
guard let fullDate = DateFormatter.getFullDate(from: date) else { | ||
return nil | ||
} | ||
|
||
let dayWithMonth = DateFormatter.getDayWithMonth(from: fullDate) | ||
return dayWithMonth | ||
} | ||
|
||
static func getDay(from date: Date = Date()) -> Int? { | ||
let stringDay = DateFormatter.dayMedium.string(from: date) | ||
guard let intDay = Int(stringDay) else { | ||
return nil | ||
} | ||
|
||
return intDay | ||
} | ||
|
||
static func getTime(from date: Date = Date()) -> String { | ||
return DateFormatter.time.string(from: date) | ||
} | ||
|
||
static func getTime(from date: String) -> String? { | ||
// Getting full date from string | ||
guard let fullDate = DateFormatter.getFullDate(from: date) else { | ||
return nil | ||
} | ||
|
||
// Convert it to string time | ||
let time = DateFormatter.getTime(from: fullDate) | ||
return time | ||
} | ||
|
||
static func getFullDate(from date: Date = Date()) -> String { | ||
return DateFormatter.fullDateMedium.string(from: date) | ||
} | ||
|
||
static func getFullDate(from date: String) -> Date? { | ||
guard let date = DateFormatter.fullDateMedium.date(from: date) else { | ||
return nil | ||
} | ||
|
||
return date | ||
} | ||
} |
Oops, something went wrong.