0

I want to know if Time.localtime returns the user local time or the server local time.

If it is the server, is it any clean way to convert a UTC time or datetime to user local time?

Tony
  • 10,088
  • 20
  • 85
  • 139

1 Answers1

2

Ruby's Time class knows nothing about any "client". You would have to inspect request headers for that. Time#getutc and Time#getlocal seem to be what you want. Notice the variant on getlocal where you can enter the TZ offset - if you pass it the client's TZ, you can get the client's local time. As I said earlier, you would have to look into the request headers to figure out which TZ it is.

EDIT: Scratch that, apparently there does not have to be a Date header in a request. So you're down to JavaScript to tell you about the time zone.

Community
  • 1
  • 1
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • Ok so there is not an automatic ruby function that looks into the request headers and convert into client's time, right? My hope was that Time.getLocal would look into the request header. – Tony May 28 '12 at 23:31
  • 1
    `Time` class doesn't know anything about HTTP. It's a time class. Ruby is not implicitly a web language like PHP is, where you might expect everything to bend one ear towards the web server. – Amadan May 28 '12 at 23:33