@@ -15,22 +15,27 @@ ui <- fluidPage(

sidebarLayout(
sidebarPanel(
timeInput("time_input", "Enter time", value = strptime("12:34:56", "%T")),
timeInput("time_input1", "Enter time", value = strptime("12:34:56", "%T")),
timeInput("time_input2", "Enter time (5 minute steps)", value = strptime("12:34:56", "%T"), minute.steps = 5),
actionButton("to_current_time", "Current time")
),

mainPanel(
textOutput("time_output")
textOutput("time_output1"),
textOutput("time_output2")
)
)
)

server <- function(input, output, session) {
output$time_output <- renderText(strftime(input$time_input, "%T"))
output$time_output1 <- renderText(strftime(input$time_input1, "%T"))
output$time_output2 <- renderText(strftime(input$time_input2, "%R"))

observeEvent(input$to_current_time, {
updateTimeInput(session, "time_input", value = Sys.time())
updateTimeInput(session, "time_input1", value = Sys.time())
updateTimeInput(session, "time_input2", value = Sys.time())
})

}

shinyApp(ui, server)
@@ -0,0 +1,12 @@
name: shinyTimeExample
title: shinyTimeExample
username:
account: burgerga
server: shinyapps.io
hostUrl: https://api.shinyapps.io/v1
appId: 115377
bundleId: 2111494
url: https://burgerga.shinyapps.io/shinyTimeExample/
when: 1558970629.32592
asMultiple: FALSE
asStatic: FALSE
@@ -26,17 +26,36 @@ var correctInputValue = function(el) {
var $el = $(el);
var val = parseFloat($el.val());
// Check if number is integer, if so put to fixed form (0.1e1 will become 1), else make 0
var newVal = (val % 1 == 0) ? val.toFixed() : 0;
var newVal = (val % 1 === 0) ? val.toFixed() : 0;
// Make 0 if out of range, alternative would be clamping.
if($el.hasClass('shinytime-hours')) {
newVal = inRange(newVal, 0, 23) ? newVal : 0;
} else {
newVal = inRange(newVal, 0, 59) ? newVal : 0;
}
// correct minute step
if($el.hasClass('shinytime-mins')){
var step = $el.attr("step");
if(step && step != 1) {
newVal = inRange(newVal, 0, 55) ? Math.round(newVal / step) * step : 55;
}
}
// Zero pad and update value
$el.val(zeroPad(newVal));
};

// From https://stackoverflow.com/a/48512262/1439843
var roundTime = function(value, minutesToRound) {

let roundTimeDate = (date) => {
let ms = 1000 * 60 * minutesToRound; // convert minutes to ms
return new Date(Math.round((new Date(date)).getTime() / ms) * ms);
};

roundedDate = roundTimeDate((new Date()).setHours(value.hour, value.min, value.sec));
return {hour: zeroPad(roundedDate.getHours()), min: zeroPad(roundedDate.getMinutes()), sec: zeroPad(roundedDate.getSeconds())};
};

var timeInputBinding = new Shiny.InputBinding();

$.extend(timeInputBinding, {
@@ -64,6 +83,8 @@ $.extend(timeInputBinding, {
},
setValue: function(el, value) {
var $inputs = $(el).find('input');
minuteSteps = $inputs.eq(1).attr("step");
if(minuteSteps && minuteSteps != 1) value = roundTime(value, minuteSteps);
$inputs.eq(0).val(value.hour);
$inputs.eq(1).val(value.min);
$inputs.eq(2).val(value.sec);
Binary file not shown.
@@ -0,0 +1,6 @@
checks
library
checks.noindex
library.noindex
data.sqlite
*.html
@@ -0,0 +1,38 @@
# Platform

|field |value |
|:--------|:----------------------------|
|version |R version 3.6.0 (2019-04-26) |
|os |Ubuntu 18.04.2 LTS |
|system |x86_64, linux-gnu |
|ui |RStudio |
|language |(EN) |
|collate |en_US.UTF-8 |
|ctype |en_US.UTF-8 |
|tz |Europe/Amsterdam |
|date |2019-05-28 |

# Dependencies

|package |old |new |Δ |
|:-----------|:--------|:--------|:--|
|shinyTime |0.2.1 |1.0.0 |* |
|BH |1.69.0-1 |1.69.0-1 | |
|crayon |1.3.4 |1.3.4 | |
|digest |0.6.19 |0.6.19 | |
|htmltools |0.3.6 |0.3.6 | |
|httpuv |1.5.1 |1.5.1 | |
|jsonlite |1.6 |1.6 | |
|later |0.8.0 |0.8.0 | |
|magrittr |1.5 |1.5 | |
|mime |0.6 |0.6 | |
|promises |1.0.1 |1.0.1 | |
|R6 |2.4.0 |2.4.0 | |
|Rcpp |1.0.1 |1.0.1 | |
|rlang |0.3.4 |0.3.4 | |
|shiny |1.3.2 |1.3.2 | |
|sourcetools |0.1.7 |0.1.7 | |
|xtable |1.8-4 |1.8-4 | |

# Revdeps

@@ -0,0 +1,5 @@
release_date: ???
rel_release_date: ???
my_news_url: ???
release_version: ???
release_details: ???
@@ -0,0 +1 @@
*Wow, no problems at all. :)*
@@ -0,0 +1 @@
*Wow, no problems at all. :)*
@@ -0,0 +1,3 @@
if(requireNamespace('spelling', quietly = TRUE))
spelling::spell_check_test(vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE)
@@ -0,0 +1,4 @@
library(testthat)
library(shinyTime)

test_check("shinyTime")
@@ -0,0 +1,10 @@
test_that("rounding time works", {
inputs <- c("00:00:00", "00:02:00", "23:59:00", "23:56:00")
outputs <- c("00:00:00", "00:00:00", "00:00:00", "23:55:00")
expect_equal(strftime(roundTime(timeStringToDate(inputs), 5), format = "%T"), outputs)

})

test_that("non-integer minutes fail", {
expect_error(roundTime(Sys.time, 0.5))
})