-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Oscar edited this page Sep 9, 2020
·
3 revisions
The ALKCore provides the following functionality:
- Provides Day, Week, Month, Year objects - Used as units of time to manipulate the date
The ALKCore provides with an easy-to-use interface for the manipulation of date objects.
- Easy Initialization of the units
- Provides convenience method which helps remove the need for boilerplate code.
- Allow the user to easily compare dates within ranges defined by Date, Week, Month and Year objects.
- Base for the unit of time.
- Take referenceDate for initialization
- Calculate the new unit of time based on Int passed as parameter
n
. Gives future time unit ifn
is positive and past time unit if then
is negative. - Calculates the number of units(distance) between the
self
and the unit . The passed unit has to be same unit as the self. We cannot pass other time unit confirming the CalendarComponent.
- A unit of time representing day of calendar.
- Contains Single date as property
- Confirm if the date occurs within the span with in the span of the self week.
- A unit of time representing day of calendar.
- Contains array of seven days starting from Sunday to Saturday.
- Gives the information related to public holiday.
- A unit of time representing months of calendar.
- Contains array of weeks
- 6 weeks(7x6 = 42 days) by default(Same as the Mac book Calendar App)
- 5~6weeks when initialized with isExcludingWeeksBeforeAndAfter is set to true. By doing so user excludes the weeks that doesn't have a single day which doesn't belong to current month.
- Confirm if the date occurs within the span with in the span of the self month.
- Confirm if the week occurs within the span with in the span of the self month. Even if single day of the week occurs with in the month its returns true.
- A unit of time representing year of calendar.
- Contains months array representing the 12 months of year
- Confirm if the date occurs within the span with in the span of the self year.
- Confirm if the occurs within the span with in the span of the self year. Even if single day of the week occurs with in the year its returns true.
- Confirm if the months occurs within the span with in the span of the self year.
Reference: https://en.wikipedia.org/wiki/Leap_year
if year % 4 == 0 && year % 100 != 0 || year % 400 == 0 {
print("Leap year")
}
final class DateFormatterCache {
static let shared = DateFormatterCache()
private init() {}
private let cachedDateFormatterQueue = DispatchQueue(label: "Almanakka.DateFormatterWithCached.String")
private var cachedDateFormattersOfString = [DateFormat : DateFormatter]()
//Date Formatter helper 新しいDateFormatterを作り代わりに作ったDateFormatter再使用される。https://github.com/MobileAct/Almanakka-iOS/wiki/_new
private(set) lazy var dateFormatter: DateFormatter = {
let formatter = DateFormatter()
return formatter
}()
//Date Formatter cache
func cachedDateFormatterOfString(with format: DateFormat) -> DateFormatter {
return cachedDateFormatterQueue.sync {
let key = format
if let cachedFormatter = cachedDateFormattersOfString[key] {
return cachedFormatter
}
let dateFormatter = DateFormatter()
dateFormatter.calendar = Calendar(identifier: .gregorian)
dateFormatter.dateFormat = format.rawValue
cachedDateFormattersOfString[key] = dateFormatter
return dateFormatter
}
}
}
Link: https://juejin.im/post/5c171582518825138d261943 https://developpaper.com/deep-optimization-of-dateformatter/ https://williamboles.me/sneaky-date-formatters-exposing-more-than-you-think/ http://jordansmith.io/performant-date-parsing/