Google timezone API - timestamp parameter - timezone

In my client application I have the Latitude & longitude information from skyhook API based on its I.P.
Now based on the latitude and longitude information I need to find out the timezone information of the client. But in the google timezone API documentation https://developers.google.com/maps/documentation/timezone/ I see that timestamp is a mandatory field. In which case what should I need to do.
Also can you kindly help me understand what does the timestamp corresponds to? For e.g :- If my Application server is in U.S.A (say PST timezone) and it makes the google API call passing the server timestamp.
If user logs into client application from India passing lat / long information, to the app server to get the timezone information what will the API provide as dstOffset and rawOffset? i.e If I add the server timestamp with dstOffset and rawOffset will I be getting the client machine timezone information?

I've been scratching my head on Google's Timezone API for a few minutes, specifically on the timestamp parameter. Maybe this will lay out the need:
In San Diego, we (now, in August) have a GMT offset of -8 because of daylight savings time. However, in November we'll have a GMT offset of -7.
So which gmt offset should Google return? -7 or -8? They're both valid, but it depends on what day you take the measurement.
Enter the Timestamp argument. Running the service now, and using a timestamp value of August 2015, I get this response:
{
"dstOffset" : 3600,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Daylight Time"
}
But if I bump the timestamp to November 2015 (once San Diego is out of daylight savings, I end up with this):
{
"dstOffset" : 0,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Standard Time"
}
In both cases the rawOffset is the same, but the DST changed because of the timestamp I provided. If you just want to know the raw timezone, the timestamp doesn't matter.
But if you want an application to reliably do something at 8:00am in San Diego in August and 8:00am in November in San Diego, you'll need to engage the timestamp.
Putting it another way, what's the value of knowing that San Diego is normally -7 hours offset from GMT. If you're working with timezones, you're likely trying to ensure that your UTC time is matched up with what a real person in that location is experiencing. As such, the DST offset is critical.

The documentation link you provided clearly states that the timestamp should be in UTC and that it is used to show the correct DST offset value. It will also control if the timeZoneName field is shown with "Standard" or "Daylight" in the name.
If you don't care about that and just want the timeZoneId field, then it doesn't matter what value you pass.

Try this
DateDiff("s", "1/1/1970", DateTime.Now)

Related

How can I format IANA timezone to US Standard timezone

I have a use-case in which I need a user to enter an availability date on the browser (which will be saved in the database in UTC format) for example
July 2nd at 6:30PM,
i am getting IANA location string using momentjs
moment.tz.guess(); //'America/New_York'
now when I do the server side rendering, I would like to render the availability date as
July 2nd at 6:30 EST
or
July 2nd at 6:30 PMT
Is there a javascript library to do this for me? how can I convert 'America/New_York' to EST?
worth mentioning it is a reactjs application
we can achieve this by momentjs. get the IANA timezone with guess() function as explained above to set the timezone and then format it with as documented in moment documents
const date = user input date saved in the database
const z = value of moment.tz.guess() which saved in db
moment(date).tz(z).format('MM/DD/YYYY hh:mm A z');

How to include a time zone in the way formatted slack dates are displayed?

The ability to use date formatting in the Slack API to display a date/time in the local timezone of the person seeing the message is great, but I'd like people to know that the date/time is in their local timezone.
Using <!date^1392734382^{date_short_pretty} {time}|2014-02-18 6:39 AM PST> will display as "Posted Feb 18, 2014 6:39 AM" if the receiver is in California, and "Posted Feb 18, 2014 8:39 AM" if the receiver is in Chicago (see here in Block Kit Builder) but there is no indication to the receivers that the date/time is in their own timezone.
Is there any way to include the receiver's time zone as part of the token string?
This is not a feature that is provided by the API. The only solution I can think of is to add some info text like "(local time)" to the datetime output in your message.

How can I get local timezone my messenger bot user?

I would like to either get the datetime of when the message was sent in user's local timezone or his/her local timezone.
How can I get that from in my bot? facebook gives the timestamp but I doubt if that timestamp is calculated based on the local timezone of the user.
The documentation gives this example:
{
"sender":{
"id":"USER_ID"
},
"recipient":{
"id":"PAGE_ID"
},
"timestamp":1458692752478,
"message":{
"mid":"mid.1457764197618:41d102a3e1ae206a38",
"text":"hello, world!",
"quick_reply": {
"payload": "DEVELOPER_DEFINED_PAYLOAD"
}
}
}
The timestamp field in this example is a Unix timestamp in terms of milliseconds. Unix timestamps are always in terms of Coordinated Universal Time (UTC). In other words, the epoch reference point is January 1st, 1970, 00:00:00.000 UTC.
Therefore, time zones are irrelevant to the message body. You should simply convert from UTC to the desired time zone (probably the user's local time zone) when the message is displayed.

yahoo weather API YQL query update frequency

select * from weather.forecast where woeid in (SELECT woeid FROM geo.placefinder WHERE text="30.7063633,76.7047791" and gflags="R")
I am using the above YQL to fetch the weather conditions for some lat, lng to show in my iOS app. The response has "pubDate":
"pubDate": "Fri, 29 May 2015 8:30 am IST",
"condition": {
"code": "28",
"date": "Fri, 29 May 2015 8:30 am IST",
"temp": "89",
"text": "Mostly Cloudy"
My concern is, will this "pubDate" ever change? I mean at 8:30 am the weather is mostly cloudy may be at 12 noon it won't be. If i access this YQL at 12 Noon the response will be same ??
Also, I have no idea about the "and gflags="R"" part of the query..
As per Yahoo developer docs here.
pubDate The date and time this forecast was posted, in the date
format defined by RFC822 Section 5, for example Mon, 25 Sep 17:25:18
-0700.
lastBuildDate The last time the feed was updated. The format is in
the date format defined by RFC822 Section 5, for example Mon, 25 Sep
17:25:18 -0700.
So, until and unless the backend gets an update of "temperature change" for a particular location, the API will not reflect any change. So that's why "lastBuildDate" is also comes in the json, which specifies when the temperature feed was last updated. So you can't do anything manually to get the temperature of a particular location for current time,
If you try to call this API in different moments during the same day you will see that lastBuildDate is the same date and time of your call.
The problem here is that the date in the condition doesn't change, and after some time the condition itself becomes obsolete, as you can easily verify using yahoo meteo app.

Problem in getting DST time?

I am trying to get the time of other GMT value by using
Calendar c1 = Calendar.getInstance(TimeZone.getTimeZone(gmt));
but how can i get the DST time at that time zone.
The TimeZone class provides a getDSTSavings() method for a specific TimeZone Object. (JavaDoc: "Returns the amount of time to be added to local standard time to get local wall clock time.")
The Calendar interface provides two getOffset() methods, which let you find out the offset from UTC. (JavaDoc: "Returns the offset of this time zone from UTC at the specified date. If Daylight Saving Time is in effect at the specified date, the offset value is adjusted with the amount of daylight saving. ")
please see this piece of code to grok the complicated ways of java time:
#Test
public void testDST() {
final TimeZone met = TimeZone.getTimeZone("MET");
Calendar gc = new GregorianCalendar(met);
final long timeInMillis = gc.getTimeInMillis();
final long gmtTime= timeInMillis-(gc.getTimeZone().getOffset(timeInMillis));
final Date gmtDate = new Date(gmtTime);
System.out.printf("%-40s: %tc\n%-40s: %tc\n%-40s: %tc\n%-40s: %d\n%-40s: %d",
"new Date() (local timezone)",new Date(),
"UTC", gmtDate ,
"now from Calendar with TC GMT+02:00",gc,
"zoneoffset",gc.get(Calendar.ZONE_OFFSET),
"dst savings",met.getDSTSavings());
}
You can also define your own SimpleTimeZone and provide custom DST rules, however, i have not found out how to get this information from the predefined TimeZones.
You should also be aware, that if TimeZone.getTimeZone(TZName) does not find the specified timezone, it does not throw an exception, but it just uses GMT, which can cause major misunderstandings.
You can find all this information (and a lot more) in javadoc for Calendar, TimeZone, Date, etc.
There are few methods available in java.util.TimeZone to get Daylight Saving Time. Please check out the BlackBerry Java Docs page.

Resources