[hyena] Use invariant date representation
- From: Gabriel Burt <gburt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hyena] Use invariant date representation
- Date: Wed, 26 May 2010 02:34:51 +0000 (UTC)
commit e7fc348b47c4ee3c9e811a144bf5c6995a464a83
Author: Gabriel Burt <gabriel burt gmail com>
Date: Thu Feb 18 15:36:44 2010 -0800
Use invariant date representation
Also, added Now and FormatVersion to the JSON output.
src/Hyena/Hyena.Metrics/MetricsCollection.cs | 7 ++++++-
src/Hyena/Hyena.Metrics/Sample.cs | 11 +++++++++--
src/Hyena/Hyena.Metrics/Tests/MetricsTests.cs | 6 ++++++
3 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/src/Hyena/Hyena.Metrics/MetricsCollection.cs b/src/Hyena/Hyena.Metrics/MetricsCollection.cs
index 834162f..1e35768 100644
--- a/src/Hyena/Hyena.Metrics/MetricsCollection.cs
+++ b/src/Hyena/Hyena.Metrics/MetricsCollection.cs
@@ -30,6 +30,7 @@ using System.Collections.Generic;
using System.Text;
using System.Reflection;
+using Hyena;
using Hyena.Json;
namespace Hyena.Metrics
@@ -74,15 +75,19 @@ namespace Hyena.Metrics
Clear ();
}
+ const int CUR_FMT_VERSION = 1;
+
public string ToJsonString ()
{
var report = new Dictionary<string, object> ();
report["ID"] = AnonymousUserId;
+ report["Now"] = DateTimeUtil.ToInvariantString (DateTime.Now);
+ report["FormatVersion"] = CUR_FMT_VERSION;
var metrics = new Dictionary<string, object> ();
foreach (var metric in this.OrderBy (m => m.Name)) {
- metrics[metric.Name] = Store.GetFor (metric).Select (s => new object [] { s.Stamp, s.Value ?? "" });
+ metrics[metric.Name] = Store.GetFor (metric).Select (s => new object [] { DateTimeUtil.ToInvariantString (s.Stamp), s.Value ?? "" });
}
report["Metrics"] = metrics;
diff --git a/src/Hyena/Hyena.Metrics/Sample.cs b/src/Hyena/Hyena.Metrics/Sample.cs
index d9491c1..fca35df 100644
--- a/src/Hyena/Hyena.Metrics/Sample.cs
+++ b/src/Hyena/Hyena.Metrics/Sample.cs
@@ -50,7 +50,14 @@ namespace Hyena.Metrics
{
MetricName = metric.Name;
Stamp = DateTime.Now;
- Value = value == null ? "" : value.ToString ();
+
+ if (value == null) {
+ Value = "";
+ } else if (value is DateTime) {
+ Value = Hyena.DateTimeUtil.ToInvariantString ((DateTime) value);
+ } else {
+ Value = value.ToString ();
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Hyena/Hyena.Metrics/Tests/MetricsTests.cs b/src/Hyena/Hyena.Metrics/Tests/MetricsTests.cs
index 2851e14..df7fe6f 100644
--- a/src/Hyena/Hyena.Metrics/Tests/MetricsTests.cs
+++ b/src/Hyena/Hyena.Metrics/Tests/MetricsTests.cs
@@ -29,6 +29,7 @@
#if ENABLE_TESTS
using System;
+using System.Linq;
using System.IO;
using NUnit.Framework;
@@ -54,6 +55,11 @@ namespace Hyena.Tests
// tests/Makefile.am runs the tests with Locale=it_IT
Assert.IsTrue (metrics_str.Contains ("it-IT"));
+
+ // Make sure DateTime samples are saved as invariant strings
+ var now = DateTime.Now;
+ var time_metric = metrics.Add ("Foo", now);
+ Assert.AreEqual (Hyena.DateTimeUtil.ToInvariantString (now), metrics.Store.GetFor (time_metric).First ().Value);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]