I am confused about time difference between LON and APAC regions. With UK day light saving, time difference between London and Singapore is 7 hours and without daylight saving, it is 8 hours.
But time difference in Sydney is 9 hours with day light saving and 11 hours without day light saving.
So my question is why there is extra one hour difference between LON and SYD
I have tested this with below code with system time zone as London
#Test
public void datetimetest(){
LocalDateTime dt1 = LocalDateTime.of(2019, 3, 19, 11, 0);
LocalDateTime dt2 = LocalDateTime.of(2019, 4, 19, 11, 0);
ZonedDateTime zonedDateTimeLon1 = dt1
.atZone(systemDefault())
.withZoneSameInstant(ZoneId.of("Europe/London"));
ZonedDateTime zonedDateTimeLon2 = dt2
.atZone(systemDefault())
.withZoneSameInstant(ZoneId.of("Europe/London"));
printZonedDateTime(zonedDateTimeLon1, "Europe/London");
printZonedDateTime(zonedDateTimeLon1, "Australia/Sydney");
printZonedDateTime(zonedDateTimeLon1, "Asia/Singapore");
printZonedDateTime(zonedDateTimeLon2, "Europe/London");
printZonedDateTime(zonedDateTimeLon2, "Australia/Sydney");
printZonedDateTime(zonedDateTimeLon2, "Asia/Singapore");
}
private static void printZonedDateTime(ZonedDateTime zonedDateTimeLon, String timeZone) {
LocalDateTime dateTime = zonedDateTimeLon
.withZoneSameInstant(ZoneId.of(timeZone))
.toLocalDateTime();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println(timeZone + "= " + dateTimeFormatter.format(dateTime));
}
Result:
Europe/London= 2019-03-19 11:00:00
Australia/Sydney= 2019-03-19 22:00:00
Asia/Singapore= 2019-03-19 19:00:00
Europe/London= 2019-04-19 11:00:00
Australia/Sydney= 2019-04-19 20:00:00
Asia/Singapore= 2019-04-19 18:00:00
As shown in results, time difference in April is 9 hours for Sydney. Can anyone please explain this
Today (March 19) Sydney is still using summer time (DST). The summer on the southern hemisphere coincides with the winter on the northern. So it’s ending around this time. So while standard time in Sydney is at offset +10:00, they are at +11:00 now. London is currently on standard time, +00:00. So the difference is 11 hours as you have observed.
Summer time begins in London (and the EU) on March 31, bringing London on offset +01:00, in turn reducing the difference to 10 hours.
Summer time ends in Sydney on April 7. They return to their standard offset of +10:00, further reducing the difference between London and Sydney to 9 hours, the difference that you observed for April 19.
Or in code:
ZoneId london = ZoneId.of("Europe/London");
ZoneId sydney = ZoneId.of("Australia/Sydney");
Instant instMarch = Instant.parse("2019-03-19T00:00:00Z");
Instant instApril = Instant.parse("2019-04-19T00:00:00Z");
System.out.println(instMarch.atZone(london));
System.out.println(instMarch.atZone(sydney));
System.out.println(instApril.atZone(london));
System.out.println(instApril.atZone(sydney));
The output is:
2019-03-19T00:00Z[Europe/London]
2019-03-19T11:00+11:00[Australia/Sydney]
2019-04-19T01:00+01:00[Europe/London]
2019-04-19T10:00+10:00[Australia/Sydney]
Please note that the current offsets are printed (Z in the first output line means offset zero).
Singapore in turn does not use summer time (at least not in 2019), so here the difference is only reduced from 8 to 7 hours when summer time begins in London.
Related
My data set is monthly from Jan 1997 to Dec 2021. I need the month code to be in the correct format, however as.date doesn't recognise the cell contents as they are. Please help.
Month BrentSpot GDP Agriculture Production Construction Services
1 Jan-1997 23.54 63.8229 53.5614 81.9963 87.2775 59.4453
2 Feb-1997 20.85 64.7182 53.9091 82.1917 87.8350 60.5018
3 Mar-1997 19.13 64.9264 54.2569 81.6142 88.6714 60.8375
4 Apr-1997 17.56 65.2327 55.1264 82.0006 89.5170 61.0981
5 May-1997 19.02 64.7336 55.8220 82.0093 89.8144 60.4470
6 Jun-1997 17.58 65.1322 56.3438 82.3350 89.4891 60.8886
Gdp_Brent_Table$Month = seq(ymd('1997-01-01'),ymd('2021-12-01'), by = 'months')
(this seemed to do the trick)
I am having trouble finding the correct currentPattern for "2018-12-21 10:57 GMT+0" when i use dateTimeFormat in Webmethods does anyone know what it should be?
yyyy-MM-dd HH:mm zZ
Taken from Integration server built in references 10.1 "Pattern String Symbols"
y = year
MM = month in year
dd = day in month
HH = hour in day (0-23)
mm = minute in hour
z = time zone
Z = RFC 822 time zone (although this is 4 digits)
I have a problem with forecasting in R.
First of all, this is an example of the original dataset (CW_data_noNA):
Loading date Year Built Vessel Type Cargo Size Week
2019-08-22 2011 Medium 30000 34
2019-09-01 2004 Aframax 80000 35
2019-08-30 2005 Panamax 60000 35
2019-09-01 2000 VLCC 270000 35
2019-08-29 2001 VLCC 270000 35
2019-09-03 2003 Suezmax 130000 36
2019-08-26 2002 Medium 30000 34
I have to create a weekly time series (showing the total number of fixed ships and the cargo capacity), and then to use naïve and simple moving average to provide one-week ahead forecast.
Weekly_base <- CW_data_noNA %>% group_by(Week) %>% summarize(Number_of_fix = n(),cargo_capacity = sum(`Cargo Size`))
Weekly_ts <- ts(Weekly_base, start = c(2019, 32), frequency = 52)
demand_training <- window(Weekly_ts, start = c(2019,32), end=c(2019,41))
demand_test <- window(Weekly_ts, start = c(2019,42))
naive(demand_training, h=1)
The problem occured with the code above is that it gives me the forcasting not for the variables (number of fix and cargo capacity) but for the week itself. This is how the result looks like:
Point Forecast Lo 80 ....
2019.788 42 -23879066 ....
Can someone help me? Thank you.
In the line where you generate your Weekly_ts, you're currently supplying the whole data frame, i.e.
Weekly_ts <- ts(Weekly_base, start = c(2019, 32), frequency = 52)
I guess the help of naive (?naive) is a bit ambiguous(?), as it states that y should be
a numeric vector or time series of class ts
and you definitely supplied an object of class ts. However, in this case you supplied multiple series when it is expecting just the one. Simply select the one you want and it should forecast the correct series
relevant_variable <- Weekly_base %>%
select(cargo_capacity)#change cargo_capacity to Number_of_fix to change variable
Weekly_ts <- ts(relevant_variable, start = c(2019, 32), frequency = 52)
Or more direct
Weekly_ts <- ts(Weekly_base$cargo_capacity, start = c(2019, 32), frequency = 52)
I have the following vector, which contains data for each day of December.
vector1 <- c(1056772, 674172, 695744, 775040, 832036,735124,820668,1790756,1329648,1195276,1267644,986716,926468,828892,826284,749504,650924,822256,3434204,2502916,1262928,1025980,1828580,923372,658824,956916,915776,1081736,869836,898736,829368)
Now I want to create a time series object on a weekly basis and used the following code snippet:
weeklyts = ts(vector1,start=c(2016,12,01), frequency=7)
However, the starting and end points are not correct. I always get the following time series:
> weeklyts
Time Series:
Start = c(2017, 5)
End = c(2021, 7)
Frequency = 7
[1] 1056772 674172 695744 775040 832036 735124 820668 1790756 1329648 1195276 1267644 986716 926468 828892 826284 749504
[17] 650924 822256 3434204 2502916 1262928 1025980 1828580 923372 658824 956916 915776 1081736 869836 898736 829368
Does anybody nows what I am doing wrong?
To get a timeseries that starts and ends as you would expect, you need to think about the timeserie. You have 31 days from december 2016.
The timeserie start option handles 2 numbers, not 3. So something like c(2016, 1) if you start with month 1 in 2016. See following example.
ts(1:12, start = c(2016, 1), frequency = 12)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2016 1 2 3 4 5 6 7 8 9 10 11 12
Now ts and daily data is an annoyance. ts cannot handle leap years. That is why you see people using a frequency of 365.25 to get an annual timeseries. To get a good december 2016 series we can do the following:
ts(vector1, start = c(2016, 336), frequency = 366)
Time Series:
Start = c(2016, 336)
End = c(2016, 366)
Frequency = 366
[1] 1056772 674172 695744 775040 832036 735124 820668 1790756 1329648 1195276 1267644 986716 926468 828892 826284 749504
[17] 650924 822256 3434204 2502916 1262928 1025980 1828580 923372 658824 956916 915776 1081736 869836 898736 829368
Note the following things that are going on:
Frequence is 366 because 2016 is a leap year
start is c(2016, 336), because 336 is the day in the year on "2016-12-01"
Personally I use xts package (and zoo) to handle daily data and use the functions in xts to aggregate to weekly timeseries. These can then be used with packages that like ts timeseries like forecast.
edit: added small xts example
my_df <- data.frame(dates = seq.Date(as.Date("2016-12-01"), as.Date("2017-01-31"), by = "day"),
var1 = rep(1:31, 2))
library(xts)
my_xts <- xts(my_df[, -1], order.by = my_df$dates)
# rollup to weekly. Dates shown are the last day in the weekperiod.
my_xts_weekly <- period.apply(my_xts, endpoints(my_xts, on = "weeks"), colSums)
head(my_xts_weekly)
[,1]
2016-12-04 10
2016-12-11 56
2016-12-18 105
2016-12-25 154
2017-01-01 172
2017-01-08 35
Depending on your needs you can transform this back into data.frames etc etc. Read the help for period.apply as you can specify your own functions in the rolling mechanism. And read the xts (and zoo) vignettes.
I have a dataframe that look like the one below.
bus_date <- as.Date(c('2017-04-03', '2017-04-04', '2017-04-06', '2017-04-11', '2017-04-13', '2017-04-17'))
sales <- c(100, 110, 120, 200, 300, 100)
daily_sales <- data.frame(bus_date, sales)
It is a sales table at the daily level.
I want to create a new variable called "Week_Start" which is the date of the business week. I have implemented various solutions which allow me to record a week number (1-52) but I need the actual week starting date.
if (bus_date is a Monday)
return(bus_date)
else
return(Monday before bus_date)
So my resulting dataframe would look like:
Week_Start <- as.Date(c('2017-04-03', '2017-04-03', '2017-04-03', '2017-04-10', '2017-04-10', '2017-04-17'))
daily_sales2 <- data.frame(bus_date, sales, Week_Start)
I know there is probably an easy way to do this, but unsure where to begin. Thanks.
From ?strptime
%w Weekday as decimal number (0–6, Sunday is 0).
%W Week of the year as decimal number (00–53) using Monday as the
first day of week (and typically with the first Monday of the year as
day 1 of week 1). The UK convention.
as.Date(format(daily_sales$bus_date, "%Y-%W-1"), format = "%Y-%W-%w")
#[1] "2017-04-03" "2017-04-03" "2017-04-03" "2017-04-10" "2017-04-10" "2017-04-17"
Here's how you can do that with floor_date from lubridate. By default, floor_date gives you the preceding Sunday. +1 gives you Monday.
library(lubridate)
daily_sales$Week_Start <- floor_date(daily_sales$bus_date,unit="week")+1
daily_sales
bus_date sales Week_Start
1 2017-04-03 100 2017-04-03
2 2017-04-04 110 2017-04-03
3 2017-04-06 120 2017-04-03
4 2017-04-11 200 2017-04-10
5 2017-04-13 300 2017-04-10
6 2017-04-17 100 2017-04-17