Ruby date today? - unexpected behavior -
i'm new ruby , trying figure out why following doesn't work expected:
2.2.1 :010 > user_date = date.today => sun, 31 may 2015 2.2.1 :011 > user_date.today? => false i'm using rails console , commands executed 1 after other (with maybe second between executions). i'm sure there nuance i'm not understanding, shouldn't second command return true instead of false? if not, why? in advance!
edit #1 - additional information requested arup
2.2.1 :013 > puts user_date.method(:today?).owner dateandtime::calculations => nil edit #2 - had hunch. i'm on eastern time , coming midnight when ran original issue. waited turn of midnight, , following works.
2.2.1 :004 > user_date = date.today => mon, 01 jun 2015 2.2.1 :005 > user_date.today? => true
date.today belongs core ruby while today? belongs rails.
under hood, today? calls date.current(rails well) instead of date.today.
going bit further, find date.current takes current rails time zone account if 1 configured. should source of mismatch.
Comments
Post a Comment