Closed dreger closed 11 years ago
Could I see an example of your problem?
Sure. Currently, the date
returned with the JSON file is formatted for UTC time and returns a string like Fri Nov 15 12:04:36 UTC 2013
.
The problem is that when I go to grab only shows that I've watched today:
shows_watched_today = entries.select { |entry| entry.date == todays_date }
The code has no context of timezones, so it searches for matches of date
in UTC time to my date
in UTC -5. The result is entries that are actually from yesterday at 7 p.m. to today at 7 p.m. and not accurate of my viewing history for just today.
I assume a fix will involve adjusting each entry's date to what it would be in the user's current timezone, and then performing the search.
I am going to look into the UTC timezone issue this evening, I will submit a pull request if I find a solution.
I believe I may have found a solution, I have to make a few tweaks to the date in the Log class but I should have a pull request for you tonight.
the 'time' module in the standard lib allows you to simply parse
the date given. and Time in cure ruby has getlocal
require 'time'
=> true
irb(main):022:0> t = Time.parse("Thu Nov 14 03:06:54 UTC 2013")
=> 2013-11-14 03:06:54 UTC
irb(main):023:0> t.getlocal
=> 2013-11-13 21:06:54 -0600
irb(main):024:0> t.getlocal.to_date == Date.parse("2013-11-13")
=> true
irb(main):025:0> t.getlocal.to_date == Date.parse("2013-11-14")
=> false
I am working on that right now
I have submitted a pull request with a fix for the timezone issue.
Great job. I just had to change Log.new(item['title'], hours, item['dateStr'])
to Log.new(item['title'], hours, item['date'])
as Time.parse() doesn't like the MM/DD/YY format.
You can use the following gem to do american dates. As america is one of the only countries that does MM/DD/YY (most do DD/MM/YY or YYYY-MM-DD) ruby does dd/mm/yy and doesn't try to be smart about it.
https://rubygems.org/gems/american_date
Also you should probably throw a Gemfile in this project
The Netflix Viewing Activity (VA) data comes in UTC time. That means for someone like me (Eastern timezone, UTC -5), Netflix says that the last five hours of my day are actually for tomorrow's VA. I've implemented a hard-coded fix for my personal timezone, but there needs to be a more flexible answer based on the user's current context.