Eliminate use of Date()

This commit is contained in:
Milos Kozak 2022-06-23 15:25:17 +02:00
parent 1b7ae4e704
commit f0a37d64f3
6 changed files with 65 additions and 81 deletions

View file

@ -148,7 +148,7 @@ class MaintenancePlugin @Inject constructor(
* @return
*/
private fun constructName(): String {
return "AndroidAPS_LOG_" + Date().time + loggerUtils.suffix
return "AndroidAPS_LOG_" + System.currentTimeMillis() + loggerUtils.suffix
}
private fun zip(zipFile: File?, files: List<File>) {

View file

@ -5,7 +5,7 @@ import java.text.SimpleDateFormat
import java.util.*
class EventNSClientNewLog(var action: String, var logText: String) : Event() {
var date = Date()
var date = System.currentTimeMillis()
private var timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())

View file

@ -85,6 +85,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
rh: ResourceHelper,
commandQueue: CommandQueue
) : PumpPluginBase(pluginDescription, injector, aapsLogger, rh, commandQueue), Pump {
@Volatile var bolusCanceled = false
@Volatile var bolusDeliveryInProgress = false
@ -95,6 +96,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
private var disposables: CompositeDisposable = CompositeDisposable()
companion object {
private const val BOLUS_RETRY_INTERVAL_MS = 2000.toLong()
private const val BOLUS_RETRIES = 5 // number of retries for cancel/get bolus status
private const val STATUS_CHECK_INTERVAL_MS = (60L * 1000)
@ -460,22 +462,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
.observeOn(aapsSchedulers.main)
.subscribe(
{
if (it.isChanged(
rh,
R.string.key_omnipod_common_expiration_reminder_enabled
) ||
it.isChanged(
rh,
R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown
) ||
it.isChanged(
rh,
R.string.key_omnipod_common_low_reservoir_alert_enabled
) ||
it.isChanged(
rh,
R.string.key_omnipod_common_low_reservoir_alert_units
)
if (it.isChanged(rh, R.string.key_omnipod_common_expiration_reminder_enabled) ||
it.isChanged(rh, R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown) ||
it.isChanged(rh, R.string.key_omnipod_common_low_reservoir_alert_enabled) ||
it.isChanged(rh, R.string.key_omnipod_common_low_reservoir_alert_units)
) {
commandQueue.customCommand(CommandUpdateAlertConfiguration(), null)
}
@ -519,7 +509,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
override val baseBasalRate: Double
get() {
val date = Date()
val date = System.currentTimeMillis()
val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0
aapsLogger.info(LTag.PUMP, "baseBasalRate: $ret at $date}")
return if (podStateManager.alarmType != null) {
@ -626,20 +616,15 @@ class OmnipodDashPumpPlugin @Inject constructor(
)
} else {
if (podStateManager.activeCommand != null) {
val sound = if (sp.getBoolean(
val sound =
if (sp.getBoolean(
R.string
.key_omnipod_common_notification_uncertain_bolus_sound_enabled,
true
.key_omnipod_common_notification_uncertain_bolus_sound_enabled, true
)
)
R.raw.boluserror
else
0
) R.raw.boluserror
else 0
showErrorDialog(
"Bolus delivery status uncertain. Refresh pod status to confirm or deny.",
sound
)
showErrorDialog("Bolus delivery status uncertain. Refresh pod status to confirm or deny.", sound)
}
}
}.toSingle {
@ -1000,12 +985,9 @@ class OmnipodDashPumpPlugin @Inject constructor(
val extended = JSONObject()
try {
val podStatus = when {
podStateManager.isPodRunning && podStateManager.isSuspended ->
"suspended"
podStateManager.isPodRunning ->
"normal"
else ->
"no active Pod"
podStateManager.isPodRunning && podStateManager.isSuspended -> "suspended"
podStateManager.isPodRunning -> "normal"
else -> "no active Pod"
}
status.put("status", podStatus)
status.put("timestamp", dateUtil.toISOString(podStateManager.lastUpdatedSystem))
@ -1122,6 +1104,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
playTestBeep()
is CommandDisableSuspendAlerts ->
disableSuspendAlerts()
else -> {
aapsLogger.warn(LTag.PUMP, "Unsupported custom command: " + customCommand.javaClass.name)
PumpEnactResult(injector).success(false).enacted(false).comment(
@ -1235,6 +1218,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
aapsLogger.debug(LTag.PUMP, "Ignoring updateAlertConfiguration because the settings did not change")
return PumpEnactResult(injector).success(true).enacted(false)
}
!podStateManager.isPodRunning -> {
aapsLogger.debug(LTag.PUMP, "Ignoring updateAlertConfiguration because there is no active pod")
return PumpEnactResult(injector).success(true).enacted(false)
@ -1356,6 +1340,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
}
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TBR_ALERTS))
}
OmnipodCommandType.RESUME_DELIVERY -> {
// We can't invalidate this command,
// and this is why it is pumpSync-ed at this point

View file

@ -15,9 +15,9 @@ class BasalProgram(
fun hasZeroUnitSegments() = segments.any { it.basalRateInHundredthUnitsPerHour == 0 }
fun rateAt(date: Date): Double {
fun rateAt(date: Long): Double {
val instance = Calendar.getInstance()
instance.time = date
instance.timeInMillis = date
val hourOfDay = instance[Calendar.HOUR_OF_DAY]
val minuteOfHour = instance[Calendar.MINUTE]
val slotIndex = hourOfDay * 2 + minuteOfHour.div(30)

View file

@ -13,6 +13,7 @@ import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.interfaces.BuildHelper
import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.interfaces.ResourceHelper
@ -39,7 +40,6 @@ import info.nightscout.androidaps.queue.events.EventQueueChanged
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.interfaces.BuildHelper
import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.ui.UIRunnable
@ -52,7 +52,6 @@ import java.time.ZonedDateTime
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import kotlin.collections.ArrayList
// TODO generify; see OmnipodErosOverviewFragment
class OmnipodDashOverviewFragment : DaggerFragment() {
@ -387,7 +386,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
rh.gs(
R.string.pump_basebasalrate,
omnipodDashPumpPlugin.model()
.determineCorrectBasalSize(podStateManager.basalProgram!!.rateAt(Date()))
.determineCorrectBasalSize(podStateManager.basalProgram!!.rateAt(System.currentTimeMillis()))
)
} else {
PLACEHOLDER

View file

@ -247,12 +247,12 @@ class OpenHumansUploader @Inject internal constructor(
tags.add("DisplayInfo")
val uploadNumber = this.uploadCounter++
val uploadDate = Date()
val uploadDate = System.currentTimeMillis()
val uploadInfo = JSONObject()
uploadInfo.put("fileVersion", 2)
uploadInfo.put("counter", uploadNumber)
uploadInfo.put("timestamp", until)
uploadInfo.put("utcOffset", TimeZone.getDefault().getOffset(uploadDate.time))
uploadInfo.put("utcOffset", TimeZone.getDefault().getOffset(uploadDate))
zos.writeFile("UploadInfo.json", uploadInfo.toString().toByteArray())
tags.add("UploadInfo")
@ -521,7 +521,7 @@ class OpenHumansUploader @Inject internal constructor(
tags = tags,
description = "AndroidAPS Database Upload",
md5 = MessageDigest.getInstance("MD5").digest(bytes).toHexString(),
creationDate = uploadDate.time
creationDate = uploadDate
)
refreshAccessTokenIfNeeded()