Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def shared_pods
pod 'LegacyUTType', '~> 0.1'
pod 'GoogleAPIClientForREST/Drive', '~> 3.3'
pod 'SnapKit'
pod 'SweeterSwift'
pod 'LibProofMode',
:git => 'https://gitlab.com/guardianproject/proofmode/libproofmode-ios.git', :branch => 'main'
#:path => '../libproofmode-ios'
Expand Down
24 changes: 24 additions & 0 deletions Save/Constants/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Constants.swift
// Save
//
// Created by navoda on 2024-11-13.
// Copyright © 2024 Open Archive. All rights reserved.
//

import Foundation
struct TimeIntervalConstants {
static let hoursInDay: Double = 24.0
static let minutuesInHour: Double = 60.0
static let secondsInDay: TimeInterval = hoursInDay * minutuesInHour * secondsInMinute
static let secondsInHour: TimeInterval = minutuesInHour * secondsInMinute
static let secondsInMinute: TimeInterval = 60.0
static let secondsInSecond: TimeInterval = 1.0
}

struct GeneralConstants {
static let percentBase: CGFloat = 100.0
static let maxSpelledOutValue: Int = 9
static let minSpelledOutValue: Int = 1
static let percentRoundedTo:Int = 2
}
34 changes: 13 additions & 21 deletions Save/Extensions/IntExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,29 @@
//

import Foundation

import SweeterSwift
import CoreGraphics

extension Int {
var day: TimeInterval { return TimeInterval.day }
var days: TimeInterval { return TimeInterval.day * Double(self) }
var day: TimeInterval { TimeIntervalConstants.secondsInDay }
var days: TimeInterval { Double(self) * day }

var hour: TimeInterval { return TimeInterval.hour }
var hours: TimeInterval { return TimeInterval.hour * Double(self) }
var hour: TimeInterval { TimeIntervalConstants.secondsInHour }
var hours: TimeInterval { Double(self) * hour }

var minute: TimeInterval { return TimeInterval.minute }
var minutes: TimeInterval { return TimeInterval.minute * Double(self) }
var minute: TimeInterval { TimeIntervalConstants.secondsInMinute }
var minutes: TimeInterval { Double(self) * minute }

var second: TimeInterval { return 1 }
var seconds: TimeInterval { return Double(self) }
var second: TimeInterval { TimeIntervalConstants.secondsInSecond }
var seconds: TimeInterval { Double(self) }

var percent: CGFloat {
return (CGFloat(self) / 100.0).rounded(toPlaces: 2)
(CGFloat(self) / GeneralConstants.percentBase).rounded(toPlaces:GeneralConstants.percentRoundedTo)
}

func spelledOut() -> String {
if self == 1 { return "one" }
if self == 2 { return "two" }
if self == 3 { return "three" }
if self == 4 { return "four" }
if self == 5 { return "five" }
if self == 6 { return "six" }
if self == 7 { return "seven" }
if self == 8 { return "eight" }
if self == 9 { return "nine" }

if self >= GeneralConstants.minSpelledOutValue && self <= GeneralConstants.maxSpelledOutValue {
return NumberFormatter.localizedString(from: NSNumber(value: self), number: .spellOut)
}
return String(self)
}
}
16 changes: 16 additions & 0 deletions Save/Extensions/TimeIntervalExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TimeIntervalExtension.swift
// Save
//
// Created by navoda on 2024-11-13.
// Copyright © 2024 Open Archive. All rights reserved.
//

import Foundation

extension TimeInterval {

static let day: TimeInterval = TimeIntervalConstants.secondsInDay
static let hour: TimeInterval = TimeIntervalConstants.secondsInHour
static let minute: TimeInterval = TimeIntervalConstants.secondsInMinute
}
5 changes: 2 additions & 3 deletions Save/Main/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ class Utils {

class func destructure(interval: TimeInterval) -> (days: Int, hours: Int, minutes: Int) {
let numDays = floor(interval / .day)
let numHours = floor((interval - (numDays * .day)) / 3600.0)
let numMinutes = floor(((interval - (numDays * .day)) - (numHours * 3600.0)) / 60.0)

let numHours = floor((interval - (numDays * .day)) / .hour)
let numMinutes = floor(((interval - (numDays * .day)) - (numHours * .hour)) / .minute)
return (Int(numDays), Int(numHours), Int(numMinutes))
}

Expand Down