mirror of
https://github.com/neon443/NearFuture.git
synced 2026-03-11 06:49:12 +00:00
fix the negative time when using the long daystill
This commit is contained in:
@@ -12,6 +12,6 @@ TEAM_ID = 8JGND254B7
|
|||||||
BUNDLE_ID = com.neon443.NearFuture
|
BUNDLE_ID = com.neon443.NearFuture
|
||||||
BUNDLE_ID_WIDGETS = com.neon443.NearFuture.widgets
|
BUNDLE_ID_WIDGETS = com.neon443.NearFuture.widgets
|
||||||
GROUP_ID = group.NearFuture
|
GROUP_ID = group.NearFuture
|
||||||
VERSION = 3.1.0
|
VERSION = 3.1.1
|
||||||
NAME = Near Future
|
NAME = Near Future
|
||||||
BUILD_NUMBER = 1
|
BUILD_NUMBER = 1
|
||||||
|
|||||||
@@ -93,22 +93,34 @@ func daysUntilEvent(_ eventDate: Date) -> (short: String, long: String) {
|
|||||||
case hours
|
case hours
|
||||||
case minutes
|
case minutes
|
||||||
}
|
}
|
||||||
func ret(days: Int = 0, hours: Int = 0, minutes: Int = 0, unit: RetUnit, future: Bool = true) -> (String, String) {
|
func ret(days: Int = 0, hours: Int = 0, minutes: Int = 0, unit: RetUnit) -> (String, String) {
|
||||||
|
var future: Bool = true
|
||||||
|
var days = days
|
||||||
|
var hours = hours
|
||||||
|
var minutes = minutes
|
||||||
|
if days < 0 || hours < 0 || minutes < 0 {
|
||||||
|
future = false
|
||||||
|
days.negate()
|
||||||
|
hours.negate()
|
||||||
|
minutes.negate()
|
||||||
|
} else {
|
||||||
|
future = true
|
||||||
|
}
|
||||||
switch unit {
|
switch unit {
|
||||||
case .days:
|
case .days:
|
||||||
return (
|
return (
|
||||||
"\(days)d",
|
"\(future ? "" : "-")\(days)d",
|
||||||
"\(days) day\(plu(-hours))"
|
"\(days) day\(plu(days)) \(future ? "" : "ago")"
|
||||||
)
|
)
|
||||||
case .hours:
|
case .hours:
|
||||||
return (
|
return (
|
||||||
"\(hours)h",
|
"\(future ? "" : "-")\(hours)h",
|
||||||
"\(hours) hour\(plu(-hours))"
|
"\(hours) hour\(plu(hours)) \(future ? "" : "ago")"
|
||||||
)
|
)
|
||||||
case .minutes:
|
case .minutes:
|
||||||
return (
|
return (
|
||||||
"\(minutes)m",
|
"\(future ? "" : "-")\(minutes)m",
|
||||||
"\(minutes) min\(plu(-minutes))"
|
"\(minutes) min\(plu(minutes)) \(future ? "" : "ago")"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,14 +144,14 @@ func daysUntilEvent(_ eventDate: Date) -> (short: String, long: String) {
|
|||||||
if days == 0 {
|
if days == 0 {
|
||||||
if hours == 0 {
|
if hours == 0 {
|
||||||
//less than 1h
|
//less than 1h
|
||||||
return ret(minutes: minutes, unit: .minutes, future: false)
|
return ret(minutes: minutes, unit: .minutes)
|
||||||
} else {
|
} else {
|
||||||
//less than 24h
|
//less than 24h
|
||||||
return ret(hours: hours, unit: .hours, future: false)
|
return ret(hours: hours, unit: .hours)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//grater than 24h
|
//grater than 24h
|
||||||
return ret(days: days, unit: .days, future: false)
|
return ret(days: days, unit: .days)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user