Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item.Date issue with timezone (UTC vs PDT) #33

Closed
homingli opened this issue Jul 20, 2016 · 11 comments
Closed

Item.Date issue with timezone (UTC vs PDT) #33

homingli opened this issue Jul 20, 2016 · 11 comments

Comments

@homingli
Copy link

In an Item for the feed that I'm pulling from...

<pubDate>Tue, 19 Jul 2016 13:14:13 PDT</pubDate>

On my local laptop with local time set to PDT, I don't have a problem:
2016-07-19 13:14:13 -0700 PDT

On my server with local time set to UTC, I have this odd timezone problem:
2016-07-19 13:14:13 +0000 PDT

@SlyMarbo
Copy link
Owner

Where exactly are you seeing the issue? Is it in the time values in the Feed structure?

@homingli
Copy link
Author

homingli commented Jul 20, 2016

I don't control the feed, but here is a scrubbed version of it...

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Title</title>
    <link>link</link>
    <link rel="alternate" href="url.rss" type="application/rss+xml" title="title"/>
    <title type="text">Title</title>
    <language>en-us</language>
    <pubDate>Wed, 20 Jul 2016 00:04:18 PDT</pubDate>
    <updated>Wed, 20 Jul 2016 00:04:18 PDT</updated>
    <generator>RSS Generator</generator>
    <ttl>5</ttl>
     <item>
      <title type="text">title</title>
      <link>link</link>
      <pubDate>Tue, 19 Jul 2016 13:14:13 PDT</pubDate>
      <guid>guid</guid>
      <description>description</description>
     </item>
  </channel>
</rss>

Test Code:

$ cat test.go
package main

import (
  "github.com/SlyMarbo/rss"
  "fmt"
)

func main() {
    feed,_ := rss.Fetch(url) // rss url scrubbed
    fmt.Println(feed.Items[0].Date)
}
$ go run test.go
2016-07-19 13:14:13 +0000 PDT

@SlyMarbo
Copy link
Owner

I'm not entirely sure what's going on here, but I can't see where it's going wrong. What happens if you call feed.Items[0].Date.UTC()?

@homingli
Copy link
Author

Really strange behavior, no change to the time, but just says UTC rather than PDT:
2016-07-19 13:14:13 +0000 UTC

Didn't really dig into it, not sure if it's related to golang/go#4001 but the issue is closed.

@SlyMarbo
Copy link
Owner

I'm afraid I don't know what to do here. Sorry :(

@homingli
Copy link
Author

Do you think you can reproduce this so to confirm it's not just me that's experiencing this issue? Thanks!

@SlyMarbo
Copy link
Owner

Yeah, I'm getting the same behaviour. I suspect it's an issue with package time.

@SlyMarbo
Copy link
Owner

Closed until we can confirm this is an issue in rss.

@homingli
Copy link
Author

@SlyMarbo The behavior is expected. I need to supply location and parse in location in order to achieve the expected result. See referenced issue golang/go#16517.

package main

import (
  "time"
  "fmt"
)

func main() {
    t, _ := time.Parse(time.RFC1123, "Tue, 26 Jul 2016 03:34:46 PDT")
    fmt.Println(t)
    loc, _ := time.LoadLocation("America/Los_Angeles")
    t, _ = time.ParseInLocation(time.RFC1123, "Tue, 26 Jul 2016 03:34:46 PDT",loc)
    fmt.Println(t)
}

output

2016-07-26 03:34:46 +0000 PDT
2016-07-26 03:34:46 -0700 PDT

How can I do that with your package?

@SlyMarbo
Copy link
Owner

Huh, I was not expecting that. I'll see what I can do.

@SlyMarbo SlyMarbo reopened this Jul 30, 2016
@SlyMarbo
Copy link
Owner

SlyMarbo commented Jul 30, 2016

Ah, it seems you can get the time package to give the intended behaviour if you override time.Local manually before using the rss functionality: https://play.golang.org/p/rWZfKkDGRI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants