Browse Source

Add Epoch Time.

pull/101/head
Abhishek 3 years ago
parent
commit
2e2d5477c5
  1. 7
      Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift
  2. 7
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  3. 3
      Clocker/Panel/Notes Popover/NotesPopover.swift
  4. 6
      Clocker/Preferences/Appearance/AppearanceViewController.swift

7
Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift

@ -20,6 +20,7 @@ public struct DateFormat {
public static let twelveHourWithZeroSeconds = "hh:mm:ss a"
public static let twelveHourWithoutSuffix = "hh:mm"
public static let twelveHourWithoutSuffixAndSeconds = "hh:mm:ss"
public static let epochTime = "epoch"
}
// Non-class type cannot conform to NSCoding!
@ -44,6 +45,7 @@ public class TimezoneData: NSObject, NSCoding {
case twelveHourPrecedingZeroSeconds = 8
case twelveHourWithoutSuffix = 10
case twelveHourWithoutSuffixAndSeconds = 11
case epochTime = 12
}
static let values = [
@ -61,6 +63,7 @@ public class TimezoneData: NSObject, NSCoding {
// Suffix
NSNumber(integerLiteral: 9): DateFormat.twelveHourWithoutSuffix,
NSNumber(integerLiteral: 10): DateFormat.twelveHourWithoutSuffixAndSeconds,
NSNumber(integerLiteral: 11): DateFormat.epochTime,
]
public var customLabel: String?
@ -266,6 +269,8 @@ public class TimezoneData: NSObject, NSCoding {
overrideFormat = .twelveHourWithoutSuffix
} else if shouldOverride == 11 {
overrideFormat = .twelveHourWithoutSuffixAndSeconds
} else if shouldOverride == 12 {
overrideFormat = .epochTime
} else {
assertionFailure("Chosen a wrong timezone format")
}
@ -318,6 +323,8 @@ public class TimezoneData: NSObject, NSCoding {
return DateFormat.twelveHourWithoutSuffix
case .twelveHourWithoutSuffixAndSeconds:
return DateFormat.twelveHourWithoutSuffixAndSeconds
case .epochTime:
return DateFormat.epochTime
}
}

7
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -31,6 +31,13 @@ extension TimezoneDataOperations {
format: dataObject.timezoneFormat(DataStore.shared().timezoneFormat()),
timezoneIdentifier: dataObject.timezone(),
locale: Locale.autoupdatingCurrent)
if (dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == DateFormat.epochTime) {
let timezone = TimeZone(identifier: dataObject.timezone())
let offset = timezone?.secondsFromGMT(for: newDate) ?? 0
let value = Int(Date().timeIntervalSince1970 + Double(offset))
return "\(value)"
}
return dateFormatter.string(from: newDate)
}

3
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -92,7 +92,8 @@ class NotesPopover: NSViewController {
"hh:mm:ss a (07:08:09 PM)",
"-- 12 Hour w/o AM/PM --",
"hh:mm (07:08)",
"hh:mm:ss (07:08:09)"]
"hh:mm:ss (07:08:09)",
"Epoch Time"]
timeFormatControl.removeAllItems()
timeFormatControl.addItems(withTitles: supportedTimeFormats)

6
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -38,7 +38,8 @@ class AppearanceViewController: ParentViewController {
"hh:mm:ss a (07:08:09 PM)",
"-- 12 Hour w/o AM/PM --",
"hh:mm (07:08)",
"hh:mm:ss (07:08:09)"]
"hh:mm:ss (07:08:09)",
"Epoch Time"]
timeFormat.removeAllItems()
timeFormat.addItems(withTitles: supportedTimeFormats)
@ -179,9 +180,6 @@ class AppearanceViewController: ParentViewController {
let selection = NSNumber(value: sender.indexOfSelectedItem)
UserDefaults.standard.set(selection, forKey: CLSelectedTimeZoneFormatKey)
Logger.log(object: ["Time Format": sender.indexOfSelectedItem == 0 ? "12 Hour Format" : "24 Hour Format"], for: "Time Format Selected")
refresh(panel: true, floating: true)
if let selectedFormat = sender.selectedItem?.title,

Loading…
Cancel
Save