Twitter - Time Zone of the Tweeet - twitter

What is the time zone used for tweets in Twitter API?

The created_at field for a tweet in the Twitter REST API gives the timestamp in UTC.
If a user has configured their timezone with Twitter, the utc_offset field gives you the difference in seconds between their timezone and UTC. So,
"utc_offset":-28800
corresponds to -28800/3600 = -8 hours from UTC.
There are a couple of suggestions that this doesn't get adjusted for daylight savings.

The timezone of each tweet is automatically converted to the local timezone. If you need UTC, you can use the .ToUniversalTime() method, for example:
myTweet.CreatedDate.ToUniversalTime();

Time zone is in the user settings under delivery options.

Unfortunately, I think It is impossible. Twitter does not store any information related to local timezone. I found that user.utc_offset are always null.

Related

Rails, Postgres and Timezone

I have table which have a datetime field named date. When doing a POST in order to insert a new row, the date sent from the client (browser) looks like 2015-11-20T14:30:00+10:00 which is actually a correct date and timezone.
However, inside Postgres this date has been inserted as 2015-11-20 04:30:00.000000, which as you can see, is not at all the same as above. I know the problem is related to the timezone. But I cannot seems to figure out a fix.
For information, I have configured my app timezone :
class Application < Rails::Application
config.time_zone = 'Brisbane'
end
Ideas?
2015-11-20T14:30:00+10:00 means that the local time of 14:30 is 10 hours ahead of UTC. Your database field reflects the correct UTC value of 04:30. This is often the desired behavior, especially if the value represent a timestamp - the date and time something occured (past tense).
In PostgreSQL, there are two different types of timestamp fields (reference)
The TIMESTAMP WITH TIME ZONE field accepts an input that contains a time zone offset. It then converts the value to UTC for storage. On retrieval, it uses the session's timezone setting.
The TIMESTAMP, or TIMESTAMP WITHOUT TIME ZONE simply stores the date and time given, ignoring any offset, and not converting to UTC.
Most of the time, you should indeed use TIMESTAMP WITH TIME ZONE. You should only use TIMESTAMP WITHOUT TIME ZONE if you need to retain the local date and time value, such as in scheduling of future events and calculation of business hours. And for those scenarios, it often makes more sense to split date and time into separate DATE and TIME fields.
One last thing - if you can avoid it, avoid using Rails time zones and use standard tzdb zones. "Australia/Brisbane" is the full tzdb identifier equivalent to the Rails "Brisbane" time zone. Refer to the section on Rails time zones at the bottom of the timezone tag wiki.
I found this gem to be incredibly useful and easy for correctly setting the time https://github.com/kbaum/browser-timezone-rails

rails - Store DateTime objects in same time zone as timestamps

When i save a DateTime schedule_time to the DB, it saves according to my local time, but the timestamps (created_at) are saved apparently in UTC (7 hours ahead of my pacific time)
So if i submit the form setting my schedule_time for right now it will be 7 hours different than my created_at.
i need to show many users their times in their own selected zone, and i also need to compare times against each other, so i want all db entries to be in the same zone. Testing on my machine, my user has his zone saved as Pacific (-7:00), but its saving schedule_time in local time, not really UTC, so when i try to display the time back like this:
#item.schedule_time.in_time_zone(#user.time_zone)
it actually takes the stored datetime and subtracts seven hours from it giving me 7 hours before i wanted. i think the best thing is to just store all the datetimes in a uniform way so i can compare them easily.
changing this value config.time_zone = 'UTC' does nothing to change the stored format of my datetime. it stores in my local time regardless, while storing the timepstamps in real UTC.
ive also tried to reformat the datetime before storing it, with in_time_zone(#user.time_zone) but it had no effect on the stored time.
if i can just get schedule_time stored in UTC just like my timestamps are stored i could make this work! any ideas?
If you want to store schedule_time converted to UTC before storing it in the database, you can include a before_save callback in your Item model to convert it as follows:
before_save { |item| item.schedule_time = item.schedule_time.utc }
sorry i was totally on the wrong track.
the issue was with the jquery date picker i was using (will_pickdate). it returns a date and time but with a +0000 time zone offset. by default, the picker autofills with the current local time, but when i submitted that, rails basically thought it was receiving a time in UTC and added it as my local time but with +0000.
in order to store the date properly i have to keep the time and date from the picker intact, but just shift the +0000 part to something appropriate:
my_time.change(offset: user_time_zone_offset)

Rails timezone and Daylight saving time

for a while I´m trying to understand how this timezone times will work, and I had a question:
Today in my country, we are in Daylight saving time (GMT-2).
So the user of my application enter a time, like 11:00AM and post the form.
Far as I know, rails will convert this date to UTC and save in the database (mysql in my case), like: 01:00PM UTC.
When I recover that record, I had to convert to local time to display. Ok?
My question is, lets suppose that this date/time represents a date/time in future, when my country gets out from summer time (GMT-3). Rails will save 01:00PM UTC? Today, in Daylight saving time, how will be the local time? And in the future, how will be this local time?
Basically, I always need to display to user 11:00AM.
thanks.
There are several places where timezone can come into play: the operating system (or probably user account) default setting, the database server, Rails environment.rb.
The key is to make sure all dates are stored with UTC time zone, then displayed in whatever your local timezone is. It sounds like you're doing that.
So your question seems to boil down to "if it's Daylight time, I want to offset by -3 hours, else offset by -2 hours". The Rails time extensions let you determine your current offset like Time.zone.now.utc_offset, and Time#dst? tells you if it's Daylight Savings Time with those two you can conditionally subtract the extra hour (3600 hundred seconds).
7 months after you asked, but perhaps skip_time_zone_conversion_for_attributes= will help - it tells AcitveRecord not to convert timezones on storage or retrieval. See ActiveRecord Timestamp which shows the example:
class Topic < ActiveRecord::Base
self.skip_time_zone_conversion_for_attributes = [:written_on]
end

Unix time stamp and timezones

quick question. I'm working with the Instagram API and everything I'm getting from their response seems to be pacific timezone. Now, I'd like to save this data to a use and display it to visitors. Problem is, visitor may be from all different timezones. So should I convert this to unix timestamp to GMT, then on display, use some sort of javascript or PHP to convert the unix timestamp to a user friendly, timezone adjust date time?
If so, my two questions are... how would I convert a timestamp in PST timezone to GMT and the how would I display that to users from different timezones? Thanks!
You can create a couple TimeZone objects and then create the DateTime object in the correct timezone the convert
$pdtTimezone = new DateTimeZone('America/Los_Angeles');
$userTimeZone = new DateTimeZone(whatever_you_need);
$orig_date_obj = new DateTime( time_to_convert , $pdtTimezone) ;
$orig_date_obj->setTimeZone($usertimezone);
You can do this by using DateTime in php to calculate the offset that you will need to convert from one time zone to another. See http://blog.serverdensity.com/2009/03/21/handling-timezone-conversion-with-php-datetime/

twitter time date stamp -Which time zone is it?

I read in a post at stackoverflow about the time date stamp for tweets that
the timezone of each tweet is automatically converted to the local timezone. If you need UTC, you can use the .ToUniversalTime() method, for example:
myTweet.CreatedDate.ToUniversalTime();
I wanted to know, when I download a tweet from Twitter's streaming API, what is the time zone. In the answer above they wrote that it is converted to the local timezone. I was not sure if that is the local zone of me (the person downloading the tweet stream) or of the person sending the tweet or of some ISP or somewhere else. Could anyone clarify this?
Thanks very much.
The API stores and returns dates and times in GMT to avoid issues with clock changes.
According to this answer, you can use the utc_offset property of the user object (which is returned with the tweet) to calculate the time relative to the user's timezone.

Resources