3 ms·
"2.days.from_now" is different from DateTime.Now.AddDays(2), because it can be broken in two parts: - 2.days is a duration, or a time delta, or time span, or w
by bad_user 13y ago
"2.days.from_now" is different from DateTime.Now.AddDays(2), because it can be broken in two parts:
- 2.days is a duration, or a time delta, or time span, or whatever you want to call it
- from_now is a method called on this duration value
This construct "2.days" is useful on its own. It's actually more useful than "DateTime.Now", as durations are often part of public interfaces, whereas usage of concrete timestamps is very often hidden. The equivalent in C# for it would be "new TimeSpan(2, 0, 0, 0)". That's much more unreadable than just "2.days" and often, instead of thinking about the problem, developers fallback to specifying time spans as Ints in seconds or similar.
On TimeZone, "2.days.from_now" is a timestamp. If the underlying library is not totally fucked up, like "java.util.Date" is, then it does have an attached timezone. Or in case this yields a Unix timestamp, it's really not a Unix timestamp unless it was calculated since 1970-01-01 00:00:00 UTC.
- viblo 13y agoI agree that the constructor isn't very easy to read for TimeSpans. But there's a shorthand, you can write "TimeSpan.FromDays(2)" to create a span of 2 days.
- MichaelGG 13y agoYou wouldn't write new TimeSpan(2,0,0,0), you'd write TimeSpan.FromDays(2). There's nothing stopping you from binding a function "days" to wrap TimeSpan.FromDays. If this is what people consider to be some pinnacle or notable point in expressiveness, yikes.
- bad_user 13y agoOh, but we can expand on that ... scala> 2.days + 10.minutes res: FiniteDuration = 2890 minutes I just don't get it. So a literal like "0.2f" to denote a Float (and not a Long) is acceptable. A literal like "300.5m" to denote a decimal and not a floating-point is acceptable. But somehow other kinds of literals for other units of measurement are not, because Dear God, magic, magic!!!