Skip to content

Replaced calls to DateTime.Now with DateTime.UtcNow to be locale agnostic #133

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Microsoft.ML.Core/Data/ProgressReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public CalculationInfo(int index, string name, ProgressChannel channel)
Index = index;
Name = name;
PendingCheckpoints = new ConcurrentQueue<KeyValuePair<DateTime, ProgressEntry>>();
StartTime = DateTime.Now;
StartTime = DateTime.UtcNow;
Channel = channel;
}
}
Expand Down Expand Up @@ -584,7 +584,7 @@ public ProgressEvent(int index, string name, DateTime startTime, ProgressEntry e
Index = index;
Name = name;
StartTime = startTime;
EventTime = DateTime.Now;
EventTime = DateTime.UtcNow;
Kind = EventKind.Progress;
ProgressEntry = entry;
}
Expand All @@ -597,7 +597,7 @@ public ProgressEvent(int index, string name, DateTime startTime, EventKind kind)
Index = index;
Name = name;
StartTime = startTime;
EventTime = DateTime.Now;
EventTime = DateTime.UtcNow;
Kind = kind;
ProgressEntry = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/Utilities/TimerScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Dispose()

// REVIEW: This is \n\n is to prevent changes across bunch of baseline files.
// Ideally we should change our comparison method to ignore empty lines.
_ch.Info("{0}\t Time elapsed(s): {1}\n\n", DateTime.Now, elapsedSeconds);
_ch.Info("{0}\t Time elapsed(s): {1}\n\n", DateTime.UtcNow, elapsedSeconds);

using (var pipe = _host.StartPipe<TelemetryMessage>("TelemetryPipe"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Microsoft.ML.Runtime.FastTree.Internal
{
Expand Down Expand Up @@ -164,7 +165,7 @@ public unsafe void SetTreeScores(int idx, double[] scores)

private LassoFit GetLassoFit(IChannel ch, int maxAllowedFeaturesPerModel)
{
DateTime startTime = DateTime.Now;
Stopwatch stopWatch = Stopwatch.StartNew();

if (maxAllowedFeaturesPerModel < 0)
{
Expand Down Expand Up @@ -450,8 +451,8 @@ private LassoFit GetLassoFit(IChannel ch, int maxAllowedFeaturesPerModel)
// First lambda was infinity; fixing it
fit.Lambdas[0] = Math.Exp(2 * Math.Log(fit.Lambdas[1]) - Math.Log(fit.Lambdas[2]));

TimeSpan duration = DateTime.Now - startTime;
ch.Info("Elapsed time for compression: {0}", duration);
stopWatch.Stop();
ch.Info("Elapsed time for compression: {0}", stopWatch.Elapsed);

return fit;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public string ToTreeEnsembleIni(FeaturesToContentMap fmap,

protected int AppendComments(StringBuilder sb, string trainingParams)
{
sb.AppendFormat("\n\n[Comments]\nC:0=Regression Tree Ensemble\nC:1=Generated using FastTree\nC:2=Created on {0}\n", DateTime.Now);
sb.AppendFormat("\n\n[Comments]\nC:0=Regression Tree Ensemble\nC:1=Generated using FastTree\nC:2=Created on {0}\n", DateTime.UtcNow);

string[] trainingParamsList = trainingParams.Split(new char[] { '\n' });
int i = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Maml/MAML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ internal static int MainCore(TlcEnvironment env, string args, bool alwaysPrintSt
Path.GetTempPath(),
"TLC");
var dumpFilePath = Path.Combine(dumpFileDir,
string.Format(CultureInfo.InvariantCulture, "Error_{0:yyyyMMdd_HHmmss}_{1}.log", DateTime.Now, Guid.NewGuid()));
string.Format(CultureInfo.InvariantCulture, "Error_{0:yyyyMMdd_HHmmss}_{1}.log", DateTime.UtcNow, Guid.NewGuid()));
bool isDumpSaved = false;
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.ResultProcessor/ResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private static bool ValidateMamlOutput(string filename, string[] rawLines, out L
Results = runResults,
PerFoldResults = foldResults,
Time = 0,
ExecutionDate = DateTime.Now.ToString()
ExecutionDate = DateTime.UtcNow.ToString()
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected virtual void InitCore(IChannel ch, int numFeatures, LinearPredictor pr
Contracts.Assert(Iteration == 0);
Contracts.Assert(Bias == 0);

ch.Trace("{0} Initializing {1} on {2} features", DateTime.Now, Name, numFeatures);
ch.Trace("{0} Initializing {1} on {2} features", DateTime.UtcNow, Name, numFeatures);
NumFeatures = numFeatures;

// We want a dense vector, to prevent memory creation during training
Expand Down Expand Up @@ -253,13 +253,13 @@ protected virtual void BeginIteration(IChannel ch)
Iteration++;
NumIterExamples = 0;

ch.Trace("{0} Starting training iteration {1}", DateTime.Now, Iteration);
ch.Trace("{0} Starting training iteration {1}", DateTime.UtcNow, Iteration);
// #if OLD_TRACING // REVIEW: How should this be ported?
if (Iteration % 20 == 0)
{
Console.Write('.');
if (Iteration % 1000 == 0)
Console.WriteLine(" {0} \t{1}", Iteration, DateTime.Now);
Console.WriteLine(" {0} \t{1}", Iteration, DateTime.UtcNow);
}
// #endif
}
Expand All @@ -269,7 +269,7 @@ protected virtual void FinishIteration(IChannel ch)
Contracts.Check(NumIterExamples > 0, NoTrainingInstancesMessage);

ch.Trace("{0} Finished training iteration {1}; iterated over {2} examples.",
DateTime.Now, Iteration, NumIterExamples);
DateTime.UtcNow, Iteration, NumIterExamples);

ScaleWeights();
#if OLD_TRACING // REVIEW: How should this be ported?
Expand Down Expand Up @@ -378,7 +378,7 @@ protected virtual void ProcessDataInstance(IChannel ch, ref VBuffer<Float> feat,
if (_numIterExamples % 5000000 == 0)
{
Host.StdOut.Write(" ");
Host.StdOut.Write(DateTime.Now);
Host.StdOut.Write(DateTime.UtcNow);
}
Host.StdOut.WriteLine();
}
Expand Down