In the table below I have customers who pay an amount at a predetermined frequency and duration. In Tableau I want to showcase the payments owed from today until expiry. I want to, conditional on the frequency determine what are their payment and when these payments will fall due.
Date-Start
Date Expiry
Customer
Frequency
Amount
01 Jan 2022
31 Jan 2025
A
Monthly
$500
01 March 2021
28 Feb 2026
B
Quarterly
$800
I have created a date diff to get number of days between today and expiry but im still stuck. How do I show a chart etc with customer A paying $500 for the next couple years? As it stands now I have one static datapoint. Essentially I want to create a series of point as long as expiry hasn't occurred.
I am trying to convert a factor into date format for specific region.
My table looks like this
Period State
2019-03-01T04:05:00+10:0 NSW
2019-03-01T04:05:00+10:00 QLD
I am trying to convert the period into a dateformat for the specific region as time zone for NSW and QLD will be different.
Already tried the lubridate package:
as.Date(df_total$Period, format = "%YYYY-%mm-%DD")
Iam getting NA while what I exactly need is the correct time for New South Wales and Queensland. Not sure if it can pick up the +10 and also change that to date at the same time.
I need help with this scenario:
1) Currently it is summer time. I need to create a time interval for June 9 Monday 6 PM - 7 PM EDT and every week after that until end of 2018. This interval will be for students to schedule appointments with a tutor. The client right now sends that as a request for creating start time at June 9 Mondays 2 PM UTC. (EDT is -4 hours offset) The server creates a start time in db for June 9 2 PM UTC and adds 7 days worth of milliseconds to create recurring
^ this causes an issue because of DST. Let's say it is right now November 5th (which is after daylights saving change). The DB still has Nov 5, 2 PM UTC saved as value. But because my timezone changed, instead of offsetting by 4 hours like I did on June, I offset by 5 hours. So the correct start time is "6 PM session in my timezone" becomes "7 PM my timezone". this is the error
the solution is either of one of two (or combination of both):
1) instead of adding 7 days worth of milisecond, you add 1 week worth of miliseconds depending on the user's timezone Currently, there's no way to extract a person's timezone based on utc offset (-400, which is right now in east coast USA, is also applicable to Canada, Carribeans, South America etc. We need to save a user's timezone as a string, rather than UTC offset count. There is an international standard for timezones)
2) ?? something else
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
timeDate stores some US holidays in GMT time zone. Given that the difference between GMT and US time zones differs throughout the year due to daylight savings, US holidays should not be stored in GMT time zone.
EST = GMT - 5 while not in daylight savings
EST = GMT - 4 from 2nd Sunday of March to 1st Sunday of November. (aka EDT)
This could bring some issues. For example:
library(timeDate)
holidayEIA <- function(x){ c(holidayNYSE(x),
USColumbusDay(x)#Data,
USVeteransDay(x)#Data)}
HolidaysEIA <- holidayEIA (2015)
#Output:
NewYork
[1] [2015-01-01 00:00:00] [2015-01-19 00:00:00] [2015-02-16 00:00:00]
[4] [2015-04-03 00:00:00] [2015-05-25 00:00:00] [2015-07-03 00:00:00]
[7] [2015-09-07 00:00:00] [2015-11-26 00:00:00] [2015-12-25 00:00:00]
[10] [2015-10-11 20:00:00] [2015-11-10 19:00:00]
Here holidayNYSE is in EST/EDT time zone, while USColumbusDay and USVeteransDay are in GMT time zone. Have to do the following to equalize:
library(timeDate)
holidayEIA <- function(x){ c(holidayNYSE(x),
USColumbusDay(x)#Data+ 14400,
USVeteransDay(x)#Data+ 18000)}
HolidaysEIA <- holidayEIA (2015)
#Output
NewYork
[1] [2015-01-01] [2015-01-19] [2015-02-16] [2015-04-03] [2015-05-25]
[6] [2015-07-03] [2015-09-07] [2015-11-26] [2015-12-25] [2015-10-12]
[11] [2015-11-11]
This is not really a question, yet given SO is a Q&A site, allow me phrase it as one. Wouldn't you agree that timeDate should store holidays in local time zones, as well as store all holidays for each country under the same time zone?
I don't work a whole lot with R, but I'll address this part of your question:
Wouldn't you agree that timeDate should store holidays in local time zones, as well as store all holidays for each country under the same time zone?
No. Fundamentally, holidays should not belong to a local time zone, nor to GMT, nor to any other time zone. In the vast majority of cases, an occurrence of a holiday is simply a calendar date, consisting of year, month, and date.
Storing it with times in a local time zone wouldn't make sense when a holiday is observed in a country with multiple time zones (like the US). Likewise, it wouldn't make sense for a holiday like Christmas Day or New Year's Day that is observed by many different people around the world.
However, when a particular individual observes a holiday, then you can take the current time zone of that individual, apply it to the calendar date, and compute the time for the start of the day, and the start of the next day. Together, those values form a half-open interval [start, end) describing how the local "day" maps to universal time.
Keep in mind that not all local days start at midnight. Some time zones have DST transitions that exclude the midnight hour, having a spring-forward from 23:59:59 to 01:00:00.
Consider the following example:
October 15th, 2017 in Brazil is the "Teacher's Day" holiday (per this list).
It also happens to be the scheduled date of the spring-forward transition (as shown here).
Stored in data, it should simply be a date: 2017-10-15.
When observed by a particular person, you take into account their time zone.
Brazil has multiple time zones, with standard time offsets ranging from UTC-2 to UTC-5 (see Wikipedia for details). Additionally, some of them observe DST and some do not.
So Teacher's day in 2017 in São Paulo is [2017-10-15T01:00-02:00, 2017-10-16T00:00-02:00), while the same holiday in Manaus is [2017-10-15T00:00-04:00, 2017-10-16T00:00-04:00).
Normalized to UTC, that's [2017-10-15T03:00Z, 2017-10-16T02:00Z) in São Paulo, but in Manaus it's [2017-10-15T04:00Z, 2017-10-16T04:00Z).
From this we can see that the concept of a "day" is not the same for everyone, neither in terms of absolute start and end, nor in terms of duration.
I have a data frame of character times that I need to average by provider, but I'm not sure how to average them using just the time without the date. For the example below:
provider time
USA 9:26:46
USDA 9:26:18
USDA 9:10:17
OIL 10:00:00
USA 6:20:56
USDA 7:19:13
OIL 11:00:00
The correct output for OIL would be the average between 10:00 and 11:00, and would look like:
provider average
OIL 10:30
Does anyone know how to average just time without incorporating date using POSIX?
mean works as expected. You can format the date to %H:%M:%S afterwards.
df <- read.table(text="provider time
USA 9:26:46
USDA 9:26:18
USDA 9:10:17
OIL 10:00:00
USA 6:20:56
USDA 7:19:13
OIL 11:00:00",head=TRUE)
df$time <- as.POSIXct(df$time,format="%T",origin="1970-01-01")
format(as.POSIXct(tapply(df$time,df$provider,mean),origin="1970-01-01"),format="%H:%M:%S")
OIL USA USDA
"10:30:00" "07:53:51" "08:38:36"
To get the providers' name :
m <- format(as.POSIXct(tapply(df$time,df$provider,mean),origin="1970-01-01"),format="%H:%M:%S")
m <- as.data.frame(m)
m$provider <- row.names(m)