Hi,
Here is my solution
library(lubridate)
#deltime=readline(prompt="Please enter deliery date and time\t") # for input of date and time
deltime="2020-04-18 06:56:47 EDT"
dTime=as.POSIXlt.character(deltime) # to pass the time in formate R accepts
sTime=Sys.time()
interval = interval(sTime, dTime) / hours(1)
if(interval<=24){
print(" Urgent Package")
}else if(interval<=48){
print("Premium Package")
}else{print("Economy Package")}
[1] "Economy Package"
- First of all, it's a bad idea using
T as a variable because this is a reserved word and defaults to TRUE (messed up your time difference).
- I also used the lubridate interval function to calculate the hours difference
- In the IF-statement, I updated the 48h interval
I don't know what type of input you are expecting from the user, but using a free text type-in to get a full date and time is a guarantee for lots of errors. Either create a simple Shiny app (using date and time inputs) or split your command line input into date and time separately (or even day, month, year and hour of day individually)
Hope this helps,
PJ