2
I’m trying to create a script that shows the sunrise and sunset with the latitudes set, but the time is not compatible. OBS: this latitude corresponds to the time of São Paulo.
library(maptools)
library(dplyr)
dateInt <- c("2017-10-11","2017-10-01")
  lon <- -46.6821862
  lat <- -23.5977319
  timezone <- 'UTC+3'
  date <- dateInt[2]
  if (length(dateInt)==1) {
    span <- 1
  }else { 
    span <- difftime(strptime(dateInt[1], format = "%Y-%m-%d")
                 ,strptime(dateInt[2], format = "%Y-%m-%d"),units="days")
    span <- as.numeric(span)
    span <- span
  }
  lon.lat <- matrix(c(lon, lat), nrow=1)
  day <- as.POSIXct(date, tz=timezone)
  sequence <- seq(from=day, length.out=span , by="days")
  #Getting datas
  sunrise <- sunriset(lon.lat, sequence, direction="sunrise", POSIXct.out=TRUE)
  sunset <- sunriset(lon.lat, sequence, direction="sunset", POSIXct.out=TRUE)
  solar_noon <- solarnoon(lon.lat, sequence, POSIXct.out=TRUE)
  day_length <- round(as.numeric(sunset$time-sunrise$time),2)
  r <- data.frame(Data=as.Date(sunrise$time),
              Nascer=format(sunrise$time, "%H:%M"),
              `Meio Dia`=format(solar_noon$time, "%H:%M"),
              Pôr=format(sunset$time, "%H:%M"),
              `Duração(Horas)` = day_length)
  #sorting dataframe by Data
  r <- r[order(r, decreasing = TRUE),]
  r <- data.frame(lapply(r, as.character), stringsAsFactors=FALSE)
  #Removing N/A
  r <- na.omit(r)
  r
Why is the schedule not compatible? What time should appear?
– Tomás Barcellos
Sp is UTC -3, but for the time to be really similar, I have to put UTC+3, even so, there is the delay around 30 minutes.
– Juny