-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add support for time zones #1
base: main
Are you sure you want to change the base?
Changes from 5 commits
8098b27
c4c7c06
6b884ed
dc733f8
d481feb
34c8491
3f12412
3a71e3c
47c0d00
ebe4d12
006ee33
829fcd7
5f5afde
eaa8905
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 |
---|---|---|
|
@@ -69,7 +69,15 @@ public struct DecimalTime { | |
public extension DecimalTime { | ||
/// Initializes a new DecimalTime with the current time | ||
init(base: Date = Date()) { | ||
let midnight = Calendar.gregorian.startOfDay(for: base) | ||
self.init(base: base, timeZone: nil) | ||
} | ||
|
||
init(base: Date = Date(), timeZone: TimeZone?) { | ||
var GregorianCalendar: Calendar = Calendar.gregorian | ||
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. Use the Swift naming conventions: lowerCamelCase for variables |
||
if let timeZone = timeZone { | ||
GregorianCalendar.timeZone = timeZone | ||
} | ||
let midnight = GregorianCalendar.startOfDay(for: base) | ||
self.init(timeSinceMidnight: base.timeIntervalSinceReferenceDate - midnight.timeIntervalSinceReferenceDate) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
import Foundation | ||
|
||
extension FrenchRepublicanDate: CustomDebugStringConvertible { | ||
public static let allMonthNames = ["Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse", "Ventôse", "Germinal", "Floréal", "Prairial", "Messidor", "Thermidor", "Fructidor", "Sansculottide"] | ||
public static let allMonthNames = ["Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse", "Ventôse", "Germinal", "Floréal", "Prairial", "Messidor", "Thermidor", "Fructidor", "Sansculottides"] | ||
public static let sansculottidesDayNames = ["Jour de la vertu", "Jour du génie", "Jour du travail", "Jour de l'opinion", "Jour des récompenses", "Jour de la révolution"] | ||
|
||
public static let shortMonthNames = ["Vend.r", "Brum.r", "Frim.r", "Niv.ô", "Pluv.ô", "Vent.ô", "Germ.l", "Flo.l", "Prai.l", "Mes.or", "Ther.or", "Fru.or", "Ss.cu"] | ||
|
@@ -40,15 +40,15 @@ extension FrenchRepublicanDate: CustomDebugStringConvertible { | |
|
||
/// Returns string as d MMMM | ||
public func toLongStringNoYear() -> String { | ||
if components.month == 13 { | ||
if components.month == 13 && !self.options.treatSansculottidesAsAMonth { | ||
return "\(FrenchRepublicanDate.sansculottidesDayNames[components.day! - 1])" | ||
} | ||
return "\(components.day!) \(monthName)" | ||
} | ||
|
||
/// Returns string as d MMM | ||
public func toShortString() -> String { | ||
if components.month == 13 { | ||
if components.month == 13 && !self.options.treatSansculottidesAsAMonth { | ||
return "\(FrenchRepublicanDate.sansculottidesShortNames[components.day! - 1])" | ||
} | ||
return "\(components.day!) \(shortMonthName)" | ||
|
@@ -132,16 +132,7 @@ extension FrenchRepublicanDate: CustomDebugStringConvertible { | |
/// Returns the wiktionary or wikipedia page link associated with the day name. | ||
public var descriptionURL: URL? { | ||
let wikipediaOverrides = [ | ||
"Belle de nuit": "Mirabilis_jalapa", | ||
"Amaryllis": "Amaryllis_(plante)", | ||
"Erable sucré": "%C3%89rable_%C3%A0_sucre", | ||
"Perce Neige": "Perce-neige", | ||
"Laurier thym": "Viorne_tin", | ||
"Thimèle": "Daphn%C3%A9_garou", | ||
"Bâton d'or": "Girofl%C3%A9e_des_murailles", | ||
"Chamerops": "Chamaerops_humilis", | ||
"Épine vinette": "%C3%89pine-vinette", | ||
"Verge d'or": "Solidago" | ||
"Belle de nuit": "Mirabilis_jalapa", "Amaryllis": "Amaryllis_(plante)", "Erable sucré": "%C3%89rable_%C3%A0_sucre", "Perce Neige": "Perce-neige", "Laurier thym": "Viorne_tin", "Thimèle": "Daphn%C3%A9_garou", "Bâton d'or": "Girofl%C3%A9e_des_murailles", "Chamerops": "Chamaerops_humilis", "Épine vinette": "%C3%89pine-vinette", "Verge d'or": "Solidago" | ||
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. avoid reformatting code, it's more readable line per line |
||
] | ||
if let override = wikipediaOverrides[dayName] { | ||
return URL(string: "https://fr.wikipedia.org/wiki/\(override)") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,17 @@ public struct FrenchRepublicanDateOptions { | |
public var romanYear: Bool | ||
public var variant: Variant | ||
|
||
/// If true, formatted dates in Sansculottides are things like "1 Sansculottides" instead of a holiday name. | ||
public var treatSansculottidesAsAMonth: Bool | ||
|
||
public init(romanYear: Bool, variant: Variant) { | ||
self.init(romanYear: romanYear, variant: variant, treatSansculottidesAsAMonth: false) | ||
} | ||
|
||
public init(romanYear: Bool, variant: Variant, treatSansculottidesAsAMonth: Bool) { | ||
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. Could use a default value of false for treatSansculottidesAsAMonth instead of duplicating here too |
||
self.romanYear = romanYear | ||
self.variant = variant | ||
self.treatSansculottidesAsAMonth = treatSansculottidesAsAMonth | ||
} | ||
|
||
public enum Variant: Int, CaseIterable { | ||
|
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.
you could just put a default argument value of nil for timeZone instead of creating another initialiser