Different creation time of the same tweet because of Time Zones - twitter

https://twitter.com/rimjhimcse1/status/1075719496030072833
The link/url conatins a tweet which is tweeted at around 5:20 PM IST and when I search the same on twitter after logging out from my profile. The time shows 3:48 AM. Which time zone this time is. Surely not UTC, as I have rechecked it doesn't match with UTC

If we look at the source code of that tweet, we can see
<a href="/rimjhimcse1/status/1075719496030072833" title="3:48 AM - 20 Dec 2018">
<span class="_timestamp" data-time="1545306488">22h</span>
(edited for clarity)
The tweet was sent at 1545306488 seconds since January 1st 1970.
That's 2018-12-20T11:48:08+00:00 - or 11:48 UTC.
So, 03:48 would be at UTC-8. That's the west coast of America - which is where Twitter is based.
Why has it chosen that time? If we look at the user object, we see:
'time_zone': None
Because the user hasn't specified a timezone, Twitter assumes they are in California.

Related

Working with DST in Rails' ActiveSupport::TimeWithZone and ActiveSupport::TimeZone

I'm having trouble getting DST offsets to matchup between ActiveSupport::TimeZone and ActiveSupport::TimeWithZone. Let's take Dublin for instance. Dublin is UTC +0 right now and UTC +1 in summer.
First we are generating a select dropdown for users, like so
ActiveSupport::TimeZone.all.collect{ |tz| ["(GMT#{ActiveSupport::TimeZone.seconds_to_utc_offset(tz.utc_offset)}) #{tz.name}", tz.name] }
But this incorrectly shows Dublin as +1. So I adjusted tz.utc_offset to tz.now.utc_offset and this correctly factors in DST, now showing Dublin as +0.
Great. Well, not quite.
After the user submits a time, we need to adjust that time using the user's selected time zone and then convert it back to UTC. However, when doing this with ActiveSupport::TimeWithZone#change, like so:
> time.change(zone: 'Dublin')
=> Tue, 30 Aug 2022 06:00:00.000000000 IST +01:00
This is still treating Dublin as +1, when it should be +0. So my question is, is there a way to factor DST into a TimeWithZone object as well, or is there another way I should be going about this?

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.

Timetable App for Rails 4

I am trying to build a timetable setup to work in conjunction with one of my Models. Before I state my question, I will give some context into the problem.
I have a Model called Appointments with the following columns:
Name(String)
Start_time(time)
End_time(time)
Appt_Date(date)
Now I can have multiple appointments in 1 day.
For Example, let's say I have the following 2 Appointment objects:
Appointment 1:
Name: Makeup Appointment
Start_time: 11:00 am
End_time: 1:00 pm
Date: March 30, 2016
Appointment 2:
Name: Daily Meetup
Start-time: 2:00 pm
End_time: 3:00 pm
Date: March 30, 2016
I would like to implement a date-picker form where you can select a date and it would render 24 rows(1 for each hour of the day) and fill in the rows with the times not available based on the appointments on that day.
For example, if I select March 30, 2016 from the date-picker, I would like to render the 24 rows and have the rows for 11am-1pm and 2:00pm-3:00pm shaded out.
The setup is like google calendars(how time slots are colored in) but with a day-to-day basis. I don't need to be able to edit these rows. I just need to view them and have them rendered with colored cells based on Appointment objects for that specific day.
My issue is, I don't know where to begin to be able to design these 24 rows that interact with appointment objects. I was thinking that perhaps I build a helper method, however even that I am pretty lost. I would appreciate some guidance on how to approach this.
Below will help you:
1.Create a file in initializer which contains list of available time slots like 10 am to 10 pm.
2.For displaying date time field , use some jquery date time picker plugin.
3.Fire an ajax when clicked on datetime picker.
4.Ajax request will come on the controller & where you have to create an active record query which will fetch all apointments according to the particular date.
5.MAke an array variable & store the time which are already booked in the above appointments.
6.Compare the available time with the booked time & edit datetimepikcer.js to shaded the booked date.

Format time to show day and month

For a project I am working on I receive date and time in this format:
2015-08-16 15:00:00 UTC
yyyy-mm-dd hh-mm-ss UTC
How can I make the time display as "Saturday, August 16th 2015 at 3:30PM"? ("15:00" would be fine as well.)
And how would I make it so it checks if the date has already passed or not, so that it only displays dates that have not passed?
How would I make it so I can so that the time display as "Saturday, August 16th 2015 at 3:30PM (15:00 would be fine as well)?
Time.parse('2015-10-20 15:23 UTC').strftime('%A, %B %dth %Y at %l:%M%p')
#=> "Tuesday, October 20th 2015 at 3:23PM"
You might have to tweak it a bit to fix the suffixes (1st, 2nd, 3rd, etc)
And how would I make it so it checks if the date has already pasted or not?
You could do it like this (I'm sure there's a simpler way):
EDIT: Yes, there is a much simpler way -- check Matt's answer.
require 'time'
if Time.parse(my_date).to_i - Time.now.to_i > 0
# my_date is in the future.
end
To start, convert your string to a Time object via Time.parse(string) (APIDock).
After that you have all of the Time class to play with.
time.strftime
time.past?

Chronic - how to set a default year when parsing a month

I got an input field where the user inputs a date, currently I'm using Chronic and the user likes it.
If the user enters last jan using Chronic and strftime I get January 2013 which is good, the issue comes when:
the user input is an upcoming month like January, the parsing I'm doing returns January 2014 and not January 2013 wich is what the user wants.
result_date = Chronic.parse(params[:date]).strftime('%B %Y')
Is there a way that I can set as default the current year? So when the user puts January it is parsed to January 2013 ?
Thanks!
I was able to figure it out!
result_date = Chronic.parse(params[:date], :context => :past).strftime('%B %Y')
Now if the user input is a single month like Jan the outcome will be January 2013
I hope it helps someone else!

Resources