Skip to content

Commit 7d70b74

Browse files
Take three for as.POSIXct() on R (< 4.3.0)
1 parent a5a398e commit 7d70b74

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: future.p2p
22
Title: A Peer-to-Peer Compute Cluster via Futureverse
3-
Version: 0.3.0-9031
3+
Version: 0.3.0-9032
44
Description: Implementation of the 'Future' API <doi:10.32614/RJ-2021-048> that resolves futures on a peer-to-peer ('P2P') compute environment. By using this future backend, you and your friends can share your spare compute resources with each other.
55
Imports:
66
future (>= 1.67.0),

R/host_cluster.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ host_cluster <- function(cluster = p2p_cluster_name(users, host = host, ssh_args
5656
now <- pico_p2p_time()
5757

5858
expires <- pico_p2p_time(delta = duration)
59-
duration <- difftime(duration, 0)
59+
duration <- difftime2(duration, 0)
6060

6161
info("Launch p2p cluster %s for %d users (%s) until %s (%s)", sQuote(cluster), length(users), commaq(users), format(Sys.time() + duration), format(duration))
6262
topic <- sprintf("%s/future.p2p", cluster_name)

R/utils-basic.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ hexpr <- function(expr, trim = TRUE, collapse = "; ", maxHead = 6L, maxTail = 3L
9191
} # hexpr()
9292

9393

94+
## Backporting for R (< 4.3.0)
9495
as_POSIXct <- function(x, tz = "", origin = as.POSIXct("1970-01-01", tz = "GMT"), ...) {
9596
as.POSIXct(x, tz = tz, origin = origin, ...)
9697
}
98+
99+
difftime2 <- function(time1, time2, tz, ..., origin = as.POSIXct("1970-01-01", tz = "GMT")) {
100+
if (missing(tz)) {
101+
time1 <- as.POSIXct(time1, origin = origin)
102+
time2 <- as.POSIXct(time2, origin = origin)
103+
} else {
104+
time1 <- as.POSIXct(time1, tz = tz, origin = origin)
105+
time2 <- as.POSIXct(time2, tz = tz, origin = origin)
106+
}
107+
108+
difftime(time1, time2, ...)
109+
}

R/waitForWorker.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ waitForWorker <- function(type,
5252
await()
5353

5454
iter <- iter + 1L
55-
dt <- difftime(Sys.time(), t0)
55+
dt <- difftime2(Sys.time(), t0)
5656
}
5757

5858
if (!finished) {

R/worker.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ run_worker <- function(cluster, worker_id, host, ssh_args, duration, channels) {
370370
now <- pico_p2p_time()
371371

372372
expires <- pico_p2p_time(delta = duration)
373-
duration <- difftime(duration, 0)
373+
duration <- difftime2(duration, 0)
374374

375375
info("get 'wormhole'")
376376
bin <- find_wormhole()
@@ -432,7 +432,7 @@ run_worker <- function(cluster, worker_id, host, ssh_args, duration, channels) {
432432
dt <- system.time({
433433
res <- pico_p2p_receive_future(p, via = via)
434434
})
435-
dt <- difftime(dt[3], 0)
435+
dt <- difftime2(dt[3], 0)
436436
info("Future %s received in %s", sQuote(future), format(dt))
437437

438438
f <- res[["future"]]
@@ -443,7 +443,7 @@ run_worker <- function(cluster, worker_id, host, ssh_args, duration, channels) {
443443
dt <- system.time({
444444
r <- tryCatch({ result(f) }, error = identity) ## Note, result() handles 'interrupt':s
445445
})
446-
dt <- difftime(dt[3], 0)
446+
dt <- difftime2(dt[3], 0)
447447
info("Future %s resolved after %s", sQuote(future), format(dt))
448448
tx_parent("resolved")
449449

@@ -453,7 +453,7 @@ run_worker <- function(cluster, worker_id, host, ssh_args, duration, channels) {
453453
dt <- system.time({
454454
pico_p2p_send_result(p, future = f, to = client, via = via)
455455
})
456-
dt <- difftime(dt[3], 0)
456+
dt <- difftime2(dt[3], 0)
457457
info("future result %s sent in %s", sQuote(future), format(dt))
458458
tx_parent("ready")
459459
state <- "ready"

0 commit comments

Comments
 (0)