last day (15 days later) » 

7:26 PM
0
Q: How to convert postgres UTC into another timezone?

AnthonyGalli.comIs there a way to convert postgres UTC time to the user's timezone or at the very least Eastern Standard Time (I'd be grateful with either answer)? I thought that there was a way to change postgres UTC time, but I don't think there is without causing a lot of issues. From what I read it would be...

 
so if you add this config.time_zone = 'Eastern Time (US & Canada)' in your application.rb and in your console if you do Habit.last.completed_at does it returns UTC time or Eastern time.?
config.time_zone let you access your time in specfic time zone using Time.zone.now or Time.zone.beginning_of_day. if you change your scope abit and add config.time_zone = 'Eastern Time (US & Canada)' in your application.rb you will acheive what you want
 
I already have that line @Athar in my application.rb: stackoverflow.com/questions/31639288/…
 
okay did you try this Habit.last.completed_at what does it return. also change your scope like this scope :incomplete, -> {where("completed_at is null OR completed_at < ?", Time.zone.now.beginning_of_day)}
 
That returns: Sun, 26 Jul 2015 12:20:13 EDT -04:00 It works in development @Athar. I'll give that scope a try.
 
okay what if you try this Habit.last.completed_at in heroku console.? what does that return.?
 
7:26 PM
Gives: Sun, 26 Jul 2015 14:10:46 EDT -04:00
Hey there!
 
hi
so the time returned is correct.?
 
Yea I think so. I made the adjustment to the scope like you suggested
 
remember me... we had a chat few days back too.:P
okay and the scope worked.?
 
Different stack account?
 
no same one...
 
7:29 PM
ah you changed your pic :)
 
yes.:)
so did the scope work.?
 
haha yes of course. Let me play with it. But why you think this works but the other didn't when the other worked in development?
 
so when we want to do something specific to time zone
we use Time.zone.now
when we do Time.now
it will return system time
Date.current also uses system time i guess( not sure about this)
so for your case. we will use Time.zone.now.beginning_of_day
that will solve the problem
27
Q: Rails 3: How to get today's date in specific timezone?

Misha MoroshkoTo get today's date I do: Date.today # => Fri, 20 May 2011 I would like to get today's date in a specific timezone, say 'Melbourne'. I have the following setting in my application.rb: config.time_zone = 'Melbourne' and I set: Time.zone = 'Melbourne' in my application controller befor...

this also supports my logic.:)
 
that makes sense now :)
 
if you want Date for current time zone
 
7:33 PM
Is this right?
=> Sun, 26 Jul 2015 14:10:46 EDT -04:00
 
you should use Date.current
=> Sun, 26 Jul 2015 14:10:46 EDT -04:00
what is this output for.?
 
completed_at. I just checked it off
It should stand for 3:34pm EST
 
i guess it is correct. what do you think.. ??
im not sure about your time.. isnt it 4 hours less
 
And okay I was using current and today interchangably
 
check the source.
you should stay with Date.current everywhere
as you are using specific time zone now
 
7:36 PM
ah okay okay
Wouldn't the above example
by 10:10am?
 
why... im sorry i didnt your question
so here my time is 12:38 am. when i set your time zone. and check time it gives Sun, 26 Jul 2015 15:38:16 EDT -04:00
so the date if you see is 26...
the same date in your case => Sun, 26 Jul 2015 14:10:46 EDT -04:00
 
hmmm
the scope isn't working
 
what happened with it..
Habit.incomplete.collect(&:completed_at)
what time does this returns.?
 
irb(main):007:0* Habit.incomplete.collect(&:completed_at)
=> [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, Fri, 24 Jul 2015 22:02:59 EDT -04:00, Fri, 24 Jul 2015 22:03:06 EDT -04:00, Fri, 24 Jul 2015 22:03:14 EDT -04:00, nil, nil, Sat, 25 Jul 2015 21:32:39 EDT -04:00, nil, Sat, 25 Jul 2015 21:32:46 EDT -04:00, Sat, 25 Jul 2015 21:32:52 EDT -04:00, Sat, 25 Jul 2015 21:33:52 EDT -04:00]
 
so the time it is returning are all specific to your time zone... isnt it.?
now when you set the completed_at for any habit
and try to see that habit completed_at field
does it returns time in EDT format.?
 
7:46 PM
well i had just clicked on a few so some should say the 26th
 
so what im seeing is in EDT time zone
the date is 26
now in scope we are fetching the habits all have dates to be less 26...
 
Actually now they are staying disappeared
I'm losing my mind lol
 
hahahhha... no worries.. redo the testing....
 
yea my terminal is running slow maybe that was why
 
i think things are going correct. but you need to be sure.. so retest is good option...
okay...
 
7:50 PM
Does this look right?
<Habit id: 9, missed_days: 0, conceal: false, likes: nil, committed: ["sun", "mon", "tue", "wed", "thu", "fri", "sat", ""], date_started: "2015-07-07 04:00:00", trigger: "get out of my running clothes", action: "pushup", target: "20", reward: "shower", user_id: 1, created_at: "2015-07-02 02:54:48", updated_at: "2015-07-26 19:48:00", order: 8, completed_at: "2015-07-26 19:48:00">
irb(main):010:0> Habit.last.completed_at
=> Sun, 26 Jul 2015 14:10:46 EDT -04:00
Shouldn't completed_at match here?
since this was the last habit I marked completed_at?
 
okay few things.. there is one thing which is saved in database
the time saved in database is the different time zone
it is actually UTC
when you do config.time_zone = "..."
it let you query things specific to your time zone
if you think of changing the time zone of database.
then you have to do in sql or some way other but honestly i wont suggest that
it is good to have sql in UTC. and in one format only.
 
Database is supposed to have timezone-neutral timestamps so they can be converted to match any user's timezone easily.
 
ah okay that's what I was trying to get to in my question but I didn't fully understand
 
@D-side correct me if i was wrong at some point above.. im also begineer.:)
 
@Athar I kinda lost track of your conversatino at some point :D
*conversation
 
7:55 PM
okay cool cool
 
And actually all I was going to suggest is something.completed_at.localtime
 
ohh... okay no worries.....:D
 
so why is
Habit.last.completed_at
=> Sun, 26 Jul 2015 14:10:46 EDT -04:00
 
But I couldn't tell if you sorted this out or not :D
 
even though I checked off other ones later than that?
I get why one is always UTC
and then they get converted to match user timezone
 
7:56 PM
Habit.last.completed_at
this will return you output in your time zone...
im again sorry i didnt get your question...
I get why one is always UTC
this line
 
Ok for example
I will check off a completed_at habit right this second
 
yes... okay..
 
then when I run
it gives me again
Habit.last.completed_at
=> Sun, 26 Jul 2015 14:10:46 EDT -04:00
 
is it updating or not.?
so you are trying to say that what so ever time you set completed_at
the time still remains => Sun, 26 Jul 2015 14:10:46 EDT -04:00
 
Yea when I run that command
Here's what that habit looks like
Habit.find(3)
=> #<Habit id: 3, missed_days: 0, conceal: false, likes: nil, committed: ["sun", "mon", "tue", "wed", "thu", "fri", "sat", ""], date_started: "2015-07-02 00:00:00", trigger: "pour tea", action: "meditate", target: "10 min", reward: "", user_id: 1, created_at: "2015-07-01 20:19:08", updated_at: "2015-07-26 19:58:14", order: 3, completed_at: "2015-07-26 19:58:14">
 
8:01 PM
habit with id 3 has completed_at completed_at: "2015-07-26 19:58:14" in utc..
what if you do h = Habit.find 3
h.completed_at
what does it returns
 
Should be the same .-.
 
?
no i think h.completed_at will be the specific to the time zone. it should not be same
 
h.completed_at
=> Sun, 26 Jul 2015 15:58:14 EDT -04:00
 
so you see the time is 4 hours less now.?
the time saved in database is utc one while when you fetch it. it becomes specific to time zone
 
Apparently, it's what that timezone config option on application.rb does. I'll try to reproduce.
 
8:05 PM
yes
sure
 
Ah okay awesome
 
@AnthonyGalli.com im guessing you are still not convinced.?
:P
 
haha no I'm convinced :]
I just wanted to understand
 
Reproduced. Yes, ActiveRecord converts values from the database with app-specific settings.
 
@D-side perfect.
yes @AnthonyGalli.com.?
 
8:07 PM
Excellect :)
You guys have been a big help!
 
perfect.
 
Alright!
 
Sometimes these things take weird turns. I appreciate you guys explaining to me why that is :]
 
Rails contains extreme amounts of magic.
Sometimes it blows minds.
 
yups... but it is awesome. i love to work in ROR.:)
 
8:09 PM
Once you master that, you can call yourself a wizard :)
 
learning never ends.:)
 
I think the greatest magic is the people who help. I would be complete lost without you guys
I'll keep plowing away. And the website I've been working on is www.personalcontrolcenter.com if you ever want to offer more input :p
I still got a ways to go before it gets real good
A lot of kinks and stuff to work out, but the main thrust of it is all there
Stay in touch. Gotta go. Computer is guna die and no outlets at this Subway :/
 
great... sure feel free to ask things
sure
:)
 

last day (15 days later) »