Google Calendar api ignores timezone - flutter

Im using the CalendarApi in flutter and in order to get events I use the list method like that:
calendarApi.events.list(
cls.calendarId,
timeZone: <specific timezone>
timeMin: DateTime.now().today().toUtc(),
timeMax: DateTime.now().tomorrow().toUtc(),
),
No matter what timezone I tried it always return the event start and end date in UTC format.
I tried using the timezones in multiple formats:
America/Los_Angeles
UTC - 08:00
GMT format
Pacific Standard Time
None of the following worked.
In addition in the in google calendar's settings the timezone is set correctly.

From the documentation:
Must be an RFC3339 timestamp with mandatory time zone offset, for example, 2011-06-03T10:00:00-07:00, 2011-06-03T10:00:00Z. Milliseconds may be provided but are ignored. If timeMax is set, timeMin must be smaller than timeMax.
Make sure the strings you are sending follow one of these pattens:
YYYY-MM-DDTHH:MM:SS±HH:MM
or
YYYY-MM-DDTHH:MM:SSZ
So for example, the time that this answer was posted would be:
2021-07-27T16:08:02+02:00
or:
2021-07-27T14:08:02Z
Where the Z signifies 'Zulu', or UTC.

Related

Material date-time pickers and zoned time string problem

I have a page with #material-ui/pickers
<TimePicker .. value={value}/> /* value == 2020-12-24T13:05:10.714Z */
The value in the example is a zoned datetime string coming the from server.
My time zone is +2:00, Ukraine/Kiev.
The problem is that rendered time is 15:05. Is this behaviour normal when input value is zoned datetime?
I would like to see 13:05. Is this the server that provides me with incorrect datetime format or is it me misusing #meterial/pickers and #date-fns ?
2020-12-24T13:05:10.714Z is an ISO-8601 datetime string. The suffix Z means that the time is in UTC (see wikipedia). The rendered time of 15:05 in your +02:00 zone matches that.
So yes, if your server meant to specify 13:05 Kiev time, it's using the wrong format or the wrong time. It should say 2020-12-24T11:05:10.714Z or 2020-12-24T13:05:10.714+02:00.

Compare String time to Local Server Time

Have a string object with a specific format of date.
Need to check if that dateStr is after the current time on local machine.
Having trouble with conversions and LocalDateTime
String dateStr = "Oct 27 2017 02:29:00 GMT+0000";
public static final String DATE_FORMAT = "MMM dd yyyy HH:mm:ss zzzZ";
I know something is fishy in the below code with the usage of LocalDateTime
public static boolean isFutureDate(String dateStr){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);
LocalDateTime dateTime = LocalDateTime.parse(dateStr, formatter);
return(dateTime.isAfter(LocalDateTime.now()));
}
Trouble is with timezones and date conversions.
Please help find the right way of checking if a dateStr is after the current local date this in Java 8?
Local… types have no time zone
You are using the wrong type for your data.
The Local… types including LocalDateTime purposely have no concept of time zone or offset-from UTC. As such they not represent a moment on the time line, only rough idea of a range of possible moments. Use LocalDateTime only when the time zone is unknown or irrelevant; never use it for an actual moment in history.
Use OffsetDateDate for values with an offset-from-UTC, a number of hours and minutes.
Use ZonedDateTime for values with an assigned time zone. A time zone such as Asia/Kolkata or America/Montreal is a particular region’s history of past, present, and future changes to its offset-from-UTC. Anomalies such as Daylight Saving Time (DST) mean a change to the offset.
If you know all your inputs are in GMT/UTC, use OffsetDateTime. If the inputs may use time zones, parse as ZonedDateTime objects.
This input data format is terrible. If you have any control, use standard ISO 8601 formats instead when exchanging date-time values as text.
All this has been covered many times already on Stack Exchange. Please search more thoroughly before posting. And search Stack Overflow to learn more. I kept my Answer here brief, as this is a duplicate.
When parsing to a LocalDateTime, you're ignoring the offset (+0000), and I'm not sure if that's what you really want.
In this case, the +0000 offset means the date/time is October 27th 2017 at 02:29 AM in UTC. When you parse to a LocalDateTime, you're ignoring the offset (so it represents only "October 27th 2017 at 02:29 AM", not attached to any timezone) and comparing to your local date/time (or the current date/time in the JVM's default timezone).
If you want to make a comparison that also considers the offset, you can parse it to OffsetDateTime and convert to Instant to compare it with the actual UTC instant, regardless of the timezone.
Also, the month name is in English (I'm assuming it's English, but you can change this accordingly), so you must a java.util.Locale in the formatter (if you don't set a locale, it'll use the JVM default, and it's not guaranteed to always be English):
// parse to OffsetDateTime (use the same formatter)
String dateStr = "Oct 27 2017 02:29:00 GMT+0000";
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm:ss zzzZ", Locale.US);
OffsetDateTime odt = OffsetDateTime.parse(dateStr, fmt);
// compare Instant's
System.out.println(odt.toInstant().isAfter(Instant.now()));
Although it works for you now, keep in mind that the default locale can be changed without notice, even at runtime. If your input has locale-sensitive date (such as month names), it's better to specify it as above.

Powershell simplest method to get current time expressed as UTC

I have reviewed the post Creating a DateTime object with a specific UTC DateTime in PowerShell, but it does not seem to directly answer the question I am asking:
What is the most direct method in PowerShell (3.0) to return a sortable string representing "now" as UTC?
I expected the correct answer to be:
Get-Date -Format (Get-Culture).DateTimeFormat.UniversalSortableDateTimePattern
OR
get-date -format u
but this is not the case.
Example: At 1300 hrs (1pm) on September 1st, 2016 in the Pacific Time Zone during DST, I get the response:
2016-09-01 13:00:00Z (the local time with a "Z" appended)
when I was expecting:
2016-09-01 20:00:00Z (correct UTC/GMT time)
So basically, my code is just getting a string representing the "local" time and appending a "Z".
Now, I know I can manipulate to get to that point, but I'm looking for the minimal (simplest, cleanest) way to get here.
Bonus Points (as if they existed): How do I get that same, sortable result, but displaying with "UTC" and/or "GMT" as the suffix. Same minimal requirement.
Probably something like this:
[DateTime]::UtcNow.ToString('u')
Which is equivalent to:
[DateTime]::UtcNow.ToString((Get-Culture).DateTimeFormat.UniversalSortableDateTimePattern)
For the bonus, I think the most straightforward way is just to replace Z with UTC:
[DateTime]::UtcNow.ToString('u').Replace('Z','UTC')
I'm assuming you'll always want UTC since that what it seems like from your question. There doesn't appear to be a format string to get just the 3 letter time zone.
I tried this, and it also gives the result I want:
"[DateTime]::UtcNow.ToString('yyyyMMdd_HHmmss_UTC')"
It is showing time in the format 20180108_152407_UTC
so you can play with the date/time formatting as you wish basically

Displaying the timezone properly in XSLT

Was using the below tag for displaying the timezone which was working fine until now when the daylight saving has happened and as our server is in UK displaying the time as 01/04/2015 03:43:00 PM + 0100, we would also like to have the timezone displayed, please advice.
Tag Used Previously:
date:format-date(date:date-time(), 'dd/MM/yyyy hh:mm:ss a Z')
Regards
Arvind
If by "properly" you mean you want it displayed as "BST" (for British Summer Time) then there isn't actually enough information in the date/time value to do this - a time-zone offset of +1 occurs in many different timezones near the Greenwich meridian.
You're using the EXSLT library for formatting dates and times. This is based on Java's SimpleDateFormat class, so you could try your luck with the timezone designator z instead of Z.
Alternatively, if you've got access to XSLT 2.0, you can use the format-dateTime() function. This suffers from the same problem (the dateTime value only stores an offset, which doesn't actually tell you the name of the timezone). But you can give the processor a clue by setting the 5th argument of format-dateTime() to "Europe/London", in which case it might be able to work it out.

Importing ICS into Google Calendar with correct timezone

I'm trying to import a simple ics file into Google calendar. However, even though I have the timezone specified, Google calendar still imports the wrong event time. (Although it does say that the wrong time is in the correct timezone.)
Here is a sample of my ics file:
BEGIN:VCALENDAR
BEGIN:VEVENT
DESCRIPTION: Test_Description
DTEND;TZID=US-Pacific:20140606T180000
DTSTART;TZID=US-Pacific:20140606T170000
LOCATION:Test_Location
SUMMARY:Test_Summary
UID:20140606T150000#NL
END:VEVENT
END:VCALENDAR
This event should show up as occurring on June 6, from 5PM-6PM Pacific Standard Time. However, on my calendar it shows up as occurring on June 6, from 10AM-11AM PST.
I think (although have not implemented) a hack to just change everything to UTC and adjust the event time accordingly might work. However, this would be a little annoying to implement and honestly Google Calendar should be able to handle this simple of an import.
Does anyone have any suggestions to deal with this, or see any bugs in my ICS file?
Thanks!
To make your ICS work with Google's "Add by URL..." specify your timestamps in UTC and add the X-WR-TIMEZONE. Timestamp must have the Z at the end to mark the timestamp as UTC:
DTSTART:20140102T110000Z
Also add the timezone specification in the VCALENDAR block like this:
X-WR-TIMEZONE:Europe/Zurich
After adding the calendar in Google Calendar, the time zone for should be set correctly in the calendar's settings.
If you are using PHP to generate the ICS, you can convert the timestamps to UTC like this:
// The timestamp in your local time and your local time zone
$timestamp = "01.01.2016 12:00";
$timezone = new DateTimeZone('Europe/Zurich');
// The UTC timezone
$utc = new DateTimeZone('UTC');
// Create a DateTime object from your timestamp using your local timezone
$datetime = DateTime::createFromFormat("d.m.Y H:i",$timestamp, $timezone);
// Set the timezone on the object to UTC.
$datetime->setTimezone($utc);
// Print the time in UTC and use the correct format for ICS
echo $datetime->format('Ymd\THis\Z');
This also works on Apple's iPhones.
Normally it is required to include VTIMEZONE objects. Many people are starting to omit that, but if you do, at least use an olson-identifier. This should be enough for google calendar to pick up the correct timezone.
An example of an olson identifier is Europe/Amsterdam. Look up the identifier the most appropriate for you. Presumably this is something like America/Los_Angeles.