3 ms·
I'm not really familiar to RoR. Is is due to Time.now getting called twice and each returns slightly different value?
by neurostimulant 5y ago
I'm not really familiar to RoR. Is is due to Time.now getting called twice and each returns slightly different value?
- deleted 5y ago[deleted]
- inopinatus 5y agoAlas, no. It's because ActiveSupport's duration arithmetic is not distributive under conversion. The expression on the left hand side advances time (as a domain object) by exactly a month, then converts the result to integer unix time. The expression on the right adds 2629746¹ to the current unix time. The conversion becomes dangerously magical in the presence of shared code that accepts both object and integer representations of time & duration. A consumer from one part of a system can inadvertently obtain different results to another unless they use identical calling conventions. [1] this is 1/12 of the mean length of a gregorian year² [2] 365.2425 days i.e. 31,556,952 seconds
- neurostimulant 5y agoOh wow. This is totally make sense when you think about it, but something that'll never cross my mind when casually checking the code. I guess this is why python's timedelta doesn't have month unit as the length of a month is highly context dependent.