Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed DateTimePrecise since it caused more problems than it solved, we

are just going to have to deal with the slightly poorer resolution of
DateTimeOffset for issue #48
  • Loading branch information...
commit d9a3970dc324bdda6742721cdabafab03537a3a8 1 parent f6014b0
@nberardi nberardi authored
View
2  src/CassandraColumnFamilyOperations.cs
@@ -43,7 +43,7 @@ public static void InsertColumn(this CassandraColumnFamily family, CassandraObje
public static void InsertColumn(this CassandraColumnFamily family, CassandraObject key, CassandraObject columnName, BytesType columnValue)
{
- InsertColumn(family, key, columnName, columnValue, DateTimePrecise.UtcNow, null);
+ InsertColumn(family, key, columnName, columnValue, DateTimeOffset.UtcNow, null);
}
public static void InsertColumn(this CassandraColumnFamily family, CassandraObject key, CassandraObject columnName, BytesType columnValue, DateTimeOffset timestamp, int? timeToLive)
View
2  src/CassandraSuperColumnFamilyOperations.cs
@@ -56,7 +56,7 @@ public static void InsertColumn(this CassandraSuperColumnFamily family, Cassandr
public static void InsertColumn(this CassandraSuperColumnFamily family, CassandraObject key, CassandraObject superColumnName, CassandraObject name, BytesType value)
{
- InsertColumn(family, key, superColumnName, name, value, DateTimePrecise.UtcNow, null);
+ InsertColumn(family, key, superColumnName, name, value, DateTimeOffset.UtcNow, null);
}
public static void InsertColumn(this CassandraSuperColumnFamily family, CassandraObject key, CassandraObject superColumnName, CassandraObject name, BytesType value, DateTimeOffset timestamp, int? timeToLive)
View
1  src/FluentCassandra.csproj
@@ -128,7 +128,6 @@
<Compile Include="CqlHelper.cs" />
<Compile Include="FluentCqlRow.cs" />
<Compile Include="ILoadable.cs" />
- <Compile Include="System\DateTimePrecise.cs" />
<Compile Include="FluentCassandraException.cs" />
<Compile Include="FluentColumn.cs">
<SubType>Code</SubType>
View
6 src/FluentColumn.cs
@@ -32,7 +32,7 @@ public FluentColumn(CassandraColumnSchema schema = null)
{
SetSchema(schema);
- ColumnTimestamp = DateTimePrecise.UtcNow;
+ ColumnTimestamp = DateTimeOffset.UtcNow;
ColumnSecondsUntilDeleted = null;
ColumnTimeUntilDeleted = null;
}
@@ -46,7 +46,7 @@ public CassandraObject ColumnName
set
{
_name = value.GetValue(GetSchema().NameType);
- ColumnTimestamp = DateTimePrecise.UtcNow;
+ ColumnTimestamp = DateTimeOffset.UtcNow;
}
}
@@ -59,7 +59,7 @@ public CassandraObject ColumnValue
set
{
_value = value.GetValue(GetSchema().ValueType);
- ColumnTimestamp = DateTimePrecise.UtcNow;
+ ColumnTimestamp = DateTimeOffset.UtcNow;
}
}
View
2  src/FluentMutation.cs
@@ -9,7 +9,7 @@ public class FluentMutation
/// </summary>
internal FluentMutation()
{
- ColumnTimestamp = DateTimePrecise.UtcNow;
+ ColumnTimestamp = DateTimeOffset.UtcNow;
}
/// <summary>
View
2  src/GuidGenerator.cs
@@ -84,7 +84,7 @@ public static DateTime GetUtcDateTime(Guid guid)
public static Guid GenerateTimeBasedGuid()
{
- return GenerateTimeBasedGuid(DateTimePrecise.UtcNowOffset, DefaultClockSequence, DefaultNode);
+ return GenerateTimeBasedGuid(DateTimeOffset.UtcNow, DefaultClockSequence, DefaultNode);
}
public static Guid GenerateTimeBasedGuid(DateTime dateTime)
View
2  src/Operations/Remove.cs
@@ -31,7 +31,7 @@ public override Void Execute()
Session.GetClient().remove(
Key,
path,
- DateTimePrecise.UtcNowOffset.ToCassandraTimestamp(),
+ DateTimeOffset.UtcNow.ToCassandraTimestamp(),
Session.WriteConsistency
);
View
127 src/System/DateTimePrecise.cs
@@ -1,127 +0,0 @@
-using System;
-using System.Diagnostics;
-
-namespace System
-{
- /// DateTimePrecise class in C# -- an improvement to DateTime.Now
- /// By jamesdbrock
- /// http://www.codeproject.com/KB/cs/DateTimePrecise.aspx
- /// Licensed via The Code Project Open License (CPOL) 1.02
- /// http://www.codeproject.com/info/cpol10.aspx
- ///
- /// DateTimePrecise provides a way to get a DateTime that exhibits the
- /// relative precision of
- /// System.Diagnostics.Stopwatch, and the absolute accuracy of DateTime.Now.
- public class DateTimePrecise
- {
- private static readonly DateTimePrecise PrivateHelperInstance = new DateTimePrecise(10);
-
- /// <summary>Returns the current date and time, just like DateTime.Now.</summary>
- public static DateTime Now
- {
- get { return PrivateHelperInstance.GetNow(); }
- }
-
- /// <summary>Returns the current date and time, just like DateTime.UtcNow.</summary>
- public static DateTime UtcNow
- {
- get { return PrivateHelperInstance.GetUtcNow(); }
- }
-
- /// <summary>Returns the current date and time, just like DateTimeOffset.Now.</summary>
- public static DateTimeOffset NowOffset
- {
- get { return PrivateHelperInstance.GetNowOffset(); }
- }
-
- /// <summary>Returns the current date and time, just like DateTimeOffset.UtcNow.</summary>
- public static DateTimeOffset UtcNowOffset
- {
- get { return PrivateHelperInstance.GetUtcNowOffset(); }
- }
-
- private const long ClockTickFrequency = 10000000;
-
- private readonly Stopwatch _stopwatch;
- private readonly long _synchronizePeriodStopwatchTicks;
- private DateTimePreciseSafeImmutable _immutable;
-
- /// <summary>Creates a new instance of DateTimePrecise.
- /// A large value of synchronizePeriodSeconds may cause arithmetic overthrow
- /// exceptions to be thrown. A small value may cause the time to be unstable.
- /// A good value is 10.
- /// synchronizePeriodSeconds = The number of seconds after which the
- /// DateTimePrecise will synchronize itself with the system clock.</summary>
- public DateTimePrecise(long synchronizePeriodSeconds)
- {
- _stopwatch = Stopwatch.StartNew();
- _stopwatch.Start();
-
- var utc = DateTime.UtcNow;
- _immutable = new DateTimePreciseSafeImmutable(utc, utc, _stopwatch.ElapsedTicks, Stopwatch.Frequency);
-
- _synchronizePeriodStopwatchTicks = synchronizePeriodSeconds * Stopwatch.Frequency;
- }
-
- /// <summary>Returns the current date and time, just like DateTime.UtcNow.</summary>
- public DateTime GetUtcNow()
- {
- var stopWatchTicks = _stopwatch.ElapsedTicks;
- var immutable = _immutable;
-
- if (stopWatchTicks < immutable.ObservedTicks + _synchronizePeriodStopwatchTicks)
- {
- return immutable.BaseTime.AddTicks(((
- stopWatchTicks - immutable.ObservedTicks) * ClockTickFrequency) / (immutable.StopWatchFrequency));
- }
- else
- {
- var utc = DateTime.UtcNow;
-
- DateTime tBaseNew = immutable.BaseTime.AddTicks(((stopWatchTicks - immutable.ObservedTicks) * ClockTickFrequency) / (immutable.StopWatchFrequency));
-
- _immutable = new DateTimePreciseSafeImmutable(
- utc,
- tBaseNew,
- stopWatchTicks,
- ((stopWatchTicks - immutable.ObservedTicks) * ClockTickFrequency * 2) / (3 * utc.Ticks - 2 * immutable.ObservedTime.Ticks - tBaseNew.Ticks));
-
- return tBaseNew;
- }
- }
-
- /// <summary>Returns the current date and time, just like DateTime.Now.</summary>
- public DateTime GetNow()
- {
- return GetUtcNow().ToLocalTime();
- }
-
- /// <summary>Returns the current date and time, just like DateTimeOffset.UtcNow.</summary>
- public DateTimeOffset GetUtcNowOffset()
- {
- return new DateTimeOffset(GetUtcNow());
- }
-
- /// <summary>Returns the current date and time, just like DateTimeOffset.Now.</summary>
- public DateTimeOffset GetNowOffset()
- {
- return new DateTimeOffset(GetNow());
- }
-
- private struct DateTimePreciseSafeImmutable
- {
- public DateTimePreciseSafeImmutable(DateTime observedTime, DateTime baseTime, long observedTicks, long stopWatchFrequency)
- {
- ObservedTime = observedTime;
- BaseTime = baseTime;
- ObservedTicks = observedTicks;
- StopWatchFrequency = Math.Max(1, stopWatchFrequency);
- }
-
- public readonly DateTime ObservedTime;
- public readonly DateTime BaseTime;
- public readonly long ObservedTicks;
- public readonly long StopWatchFrequency;
- }
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.