Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Implement issue# 9337: There's no Duration.max. #387

Merged
merged 3 commits into from Jan 18, 2013

Conversation

Projects
None yet
2 participants

@ghost Unknown commented on an outdated diff Jan 18, 2013

src/core/time.d
@@ -73,15 +73,15 @@ ulong mach_absolute_time();
Use the $(LREF dur) function or on of its non-generic aliases to create
$(D Duration)s.
- You cannot create a duration of months or years because the variable number
- of days in a month or a year makes it so that you cannot convert between
- months or years and smaller units without a specific date. Any type or
- function which handles months or years has other functions for handling
- those rather than using durations. For instance, $(XREF datetime, Date) has
- $(D addYears) and $(D addMonths) for adding years and months, rather than
- creating a duration of years or months and adding that to a
- $(XREF datetime, Date). If you're dealing with weeks or smaller, however,
- durations are what you use.
+ It's not possible to create a Duration of months or years, because the
+ variable number of days in a month or year makes it so that it's not
@ghost

ghost Jan 18, 2013

Just to shorten it a bit: makes it so that it's not possible -> makes it impossible

@andralex andralex commented on an outdated diff Jan 18, 2013

src/core/time.d
@@ -115,11 +115,29 @@ public:
+/
static @property @safe pure nothrow Duration zero() { return Duration(0); }
+ /++
+ Largest $(D Duration) possible.
+ +/
+ static @property @safe pure nothrow Duration max() { return Duration(long.max); }
+
+ /++
+ Smallest $(D Duration) possible.
@andralex

andralex Jan 18, 2013

Owner

This may be confusing, I'm thinking "smallest" would be zero. How about adding a brief explanation a la "since duration may be negative, this is the largest negative duration possible".

jmdavis added some commits Jan 18, 2013

@jmdavis jmdavis Implement issue# 9337: There's no Duration.max.
Added Duration.max and Duration.min.
606a6e5
@jmdavis jmdavis Added TickDuration.max and TickDuration.min. f742648
@jmdavis jmdavis Some tweaks to Duration's documentation.
It erroneously mentioned addYears and addMonths as functions on
std.datetime.Date.
cc2b137
Member

jmdavis commented Jan 18, 2013

Adjustments made per suggestions.

@andralex andralex added a commit that referenced this pull request Jan 18, 2013

@andralex andralex Merge pull request #387 from jmdavis/time
Implement issue# 9337: There's no Duration.max.
e5c84ff

@andralex andralex merged commit e5c84ff into dlang:master Jan 18, 2013

Owner

andralex commented Jan 18, 2013

merged -- thanks!

Owner

andralex commented Jan 18, 2013

@jmdavis One more thought - wouldn't it be even cheaper if we made min and max enums?

Member

jmdavis commented Jan 19, 2013

@andralex > One more thought - wouldn't it be even cheaper if we made min and max enums?

I hadn't thought of that. However, that doesn't seem to work. I get errors like this

src/core/time.d(116): Error: cannot create a struct until its size is determined

when I try and make either zero, min, or max into enums, even if I put them at the end of the struct. That seems rather odd to me given that the enum isn't actually part of the struct - just part of its namespace really - but apparently it doesn't work right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment