Skip to content

Commit

Permalink
Merge pull request #3666 from burner/std.datatime_doc_update_9_9
Browse files Browse the repository at this point in the history
std.datetime_doc_update 9 of 9
  • Loading branch information
jmdavis committed Sep 18, 2015
2 parents 588029d + b016472 commit a327ed3
Showing 1 changed file with 53 additions and 100 deletions.
153 changes: 53 additions & 100 deletions std/datetime.d
Expand Up @@ -26540,11 +26540,6 @@ public:

Throws:
$(LREF DateTimeException) if the given time zone could not be found.

Examples:
--------------------
auto tz = TimeZone.getTimeZone("America/Los_Angeles");
--------------------
+/
static immutable(TimeZone) getTimeZone(string name) @safe
{
Expand All @@ -26571,6 +26566,12 @@ auto tz = TimeZone.getTimeZone("America/Los_Angeles");
}
}

///
unittest
{
auto tz = TimeZone.getTimeZone("America/Los_Angeles");
}

// The purpose of this is to handle the case where a Windows time zone is
// new and exists on an up-to-date Windows box but does not exist on Windows
// boxes which have not been properly updated. The "date added" is included
Expand Down Expand Up @@ -28215,15 +28216,6 @@ public:
Throws:
$(LREF DateTimeException) if the given time zone could not be found or
$(D FileException) if the TZ Database file could not be opened.

Examples:
--------------------
auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles");

assert(tz.name == "America/Los_Angeles");
assert(tz.stdName == "PST");
assert(tz.dstName == "PDT");
--------------------
+/
//TODO make it possible for tzDatabaseDir to be gzipped tar file rather than an uncompressed
// directory.
Expand Down Expand Up @@ -28531,6 +28523,19 @@ assert(tz.dstName == "PDT");
throw new DateTimeException("Not a valid TZ data file", __FILE__, __LINE__, e);
}

///
unittest
{
version(Posix)
{
auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles");

assert(tz.name == "America/Los_Angeles");
assert(tz.stdName == "PST");
assert(tz.dstName == "PDT");
}
}

/++
Returns a list of the names of the time zones installed on the system.

Expand Down Expand Up @@ -29980,70 +29985,10 @@ version(Windows) unittest
of the system clock varies from system to system, and other system-dependent
and situation-dependent stuff (such as the overhead of a context switch
between threads) can also affect $(D StopWatch)'s accuracy.

Examples:
--------------------
void foo()
{
StopWatch sw;
enum n = 100;
TickDuration[n] times;
TickDuration last = TickDuration.from!"seconds"(0);
foreach(i; 0..n)
{
sw.start(); //start/resume mesuring.
foreach(unused; 0..1_000_000)
bar();
sw.stop(); //stop/pause measuring.
//Return value of peek() after having stopped are the always same.
writeln((i + 1) * 1_000_000, " times done, lap time: ",
sw.peek().msecs, "[ms]");
times[i] = sw.peek() - last;
last = sw.peek();
}
real sum = 0;
// To know the number of seconds,
// use properties of TickDuration.
// (seconds, msecs, usecs, hnsecs)
foreach(t; times)
sum += t.hnsecs;
writeln("Average time: ", sum/n, " hnsecs");
}
--------------------
+/
@safe struct StopWatch
{
public:
//Verify Example
@safe unittest
{
void writeln(S...)(S args){}
static void bar() {}

StopWatch sw;
enum n = 100;
TickDuration[n] times;
TickDuration last = TickDuration.from!"seconds"(0);
foreach(i; 0..n)
{
sw.start(); //start/resume mesuring.
foreach(unused; 0..1_000_000)
bar();
sw.stop(); //stop/pause measuring.
//Return value of peek() after having stopped are the always same.
writeln((i + 1) * 1_000_000, " times done, lap time: ",
sw.peek().msecs, "[ms]");
times[i] = sw.peek() - last;
last = sw.peek();
}
real sum = 0;
// To get the number of seconds,
// use properties of TickDuration.
// (seconds, msecs, usecs, hnsecs)
foreach(t; times)
sum += t.hnsecs;
writeln("Average time: ", sum/n, " hnsecs");
}

/++
Auto start with constructor.
Expand Down Expand Up @@ -30094,6 +30039,7 @@ public:
_timeMeasured.length = 0;
}

///
@safe unittest
{
StopWatch sw;
Expand Down Expand Up @@ -30241,6 +30187,37 @@ private:
TickDuration _timeMeasured;
}

///
@safe unittest
{
void writeln(S...)(S args){}
static void bar() {}

StopWatch sw;
enum n = 100;
TickDuration[n] times;
TickDuration last = TickDuration.from!"seconds"(0);
foreach(i; 0..n)
{
sw.start(); //start/resume mesuring.
foreach(unused; 0..1_000_000)
bar();
sw.stop(); //stop/pause measuring.
//Return value of peek() after having stopped are the always same.
writeln((i + 1) * 1_000_000, " times done, lap time: ",
sw.peek().msecs, "[ms]");
times[i] = sw.peek() - last;
last = sw.peek();
}
real sum = 0;
// To get the number of seconds,
// use properties of TickDuration.
// (seconds, msecs, usecs, hnsecs)
foreach(t; times)
sum += t.hnsecs;
writeln("Average time: ", sum/n, " hnsecs");
}


/++
Benchmarks code for speed assessment and comparison.
Expand Down Expand Up @@ -30359,21 +30336,6 @@ private:
baseFunc = The function to become the base of the speed.
targetFunc = The function that wants to measure speed.
times = The number of times each function is to be executed.

Examples:
--------------------
void f1() {
// ...
}
void f2() {
// ...
}

void main() {
auto b = comparingBenchmark!(f1, f2, 0x80);
writeln(b.point);
}
--------------------
+/
ComparingBenchmarkResult comparingBenchmark(alias baseFunc,
alias targetFunc,
Expand All @@ -30383,24 +30345,15 @@ ComparingBenchmarkResult comparingBenchmark(alias baseFunc,
return ComparingBenchmarkResult(t[0], t[1]);
}

///
@safe unittest
{
void f1x() {}
void f2x() {}
@safe void f1o() {}
@safe void f2o() {}
auto b1 = comparingBenchmark!(f1o, f2o, 1)(); // OK
//static auto b2 = comparingBenchmark!(f1x, f2x, 1); // NG
}

unittest
{
void f1x() {}
void f2x() {}
@safe void f1o() {}
@safe void f2o() {}
auto b1 = comparingBenchmark!(f1o, f2o, 1)(); // OK
auto b2 = comparingBenchmark!(f1x, f2x, 1)(); // OK
//writeln(b1.point);
}

//Bug# 8450
Expand Down

0 comments on commit a327ed3

Please sign in to comment.