Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added back in support for the new DateTimePrecise for issue #66

  • Loading branch information...
commit 55425c900943c8ad6a85bd1d46f2684f19c0fe3c 1 parent 5bb2c69
@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, DateTimeOffset.UtcNow, null);
+ InsertColumn(family, key, columnName, columnValue, DateTimePrecise.UtcNowOffset, 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, DateTimeOffset.UtcNow, null);
+ InsertColumn(family, key, superColumnName, name, value, DateTimePrecise.UtcNowOffset, null);
}
public static void InsertColumn(this CassandraSuperColumnFamily family, CassandraObject key, CassandraObject superColumnName, CassandraObject name, BytesType value, DateTimeOffset timestamp, int? timeToLive)
View
6 src/FluentColumn.cs
@@ -32,7 +32,7 @@ public FluentColumn(CassandraColumnSchema schema = null)
{
SetSchema(schema);
- ColumnTimestamp = DateTimeOffset.UtcNow;
+ ColumnTimestamp = DateTimePrecise.UtcNowOffset;
ColumnSecondsUntilDeleted = null;
ColumnTimeUntilDeleted = null;
}
@@ -46,7 +46,7 @@ public CassandraObject ColumnName
set
{
_name = value.GetValue(GetSchema().NameType);
- ColumnTimestamp = DateTimeOffset.UtcNow;
+ ColumnTimestamp = DateTimePrecise.UtcNowOffset;
}
}
@@ -59,7 +59,7 @@ public CassandraObject ColumnValue
set
{
_value = value.GetValue(GetSchema().ValueType);
- ColumnTimestamp = DateTimeOffset.UtcNow;
+ ColumnTimestamp = DateTimePrecise.UtcNowOffset;
}
}
View
2  src/FluentMutation.cs
@@ -9,7 +9,7 @@ public class FluentMutation
/// </summary>
internal FluentMutation()
{
- ColumnTimestamp = DateTimeOffset.UtcNow;
+ ColumnTimestamp = DateTimePrecise.UtcNowOffset;
}
/// <summary>
View
2  src/GuidGenerator.cs
@@ -84,7 +84,7 @@ public static DateTime GetUtcDateTime(Guid guid)
public static Guid GenerateTimeBasedGuid()
{
- return GenerateTimeBasedGuid(DateTimeOffset.UtcNow, DefaultClockSequence, DefaultNode);
+ return GenerateTimeBasedGuid(DateTimePrecise.UtcNowOffset, DefaultClockSequence, DefaultNode);
}
public static Guid GenerateTimeBasedGuid(DateTime dateTime)
View
7 src/Operations/Remove.cs
@@ -1,15 +1,10 @@
using System;
-using Apache.Cassandra;
using FluentCassandra.Types;
namespace FluentCassandra.Operations
{
public class Remove : ColumnFamilyOperation<Void>
{
- /*
- * remove(keyspace, key, column_path, timestamp, consistency_level)
- */
-
public CassandraObject Key { get; private set; }
public CassandraObject SuperColumnName { get; private set; }
@@ -31,7 +26,7 @@ public override Void Execute()
Session.GetClient().remove(
Key,
path,
- DateTimeOffset.UtcNow.ToCassandraTimestamp(),
+ DateTimePrecise.UtcNowOffset.ToCassandraTimestamp(),
Session.WriteConsistency
);
View
20 src/TimestampHelper.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
namespace FluentCassandra
{
@@ -12,30 +10,38 @@ public static class TimestampHelper
public static readonly long MaxUnixMilliseconds;
public static readonly long MaxUnixMicroseconds;
+ public const long TicksInOneMicrosecond = 10L;
+ public const long TicksInOneMillisecond = 10000L;
+ public const long TicksInOneSecond = 10000000L;
+
static TimestampHelper()
{
UnixStart = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
MaxUnixSeconds = Convert.ToInt64((DateTimeOffset.MaxValue - UnixStart).TotalSeconds);
MaxUnixMilliseconds = Convert.ToInt64((DateTimeOffset.MaxValue - UnixStart).TotalMilliseconds);
- MaxUnixMicroseconds = Convert.ToInt64((DateTimeOffset.MaxValue - UnixStart).Ticks / 10L);
+ MaxUnixMicroseconds = Convert.ToInt64((DateTimeOffset.MaxValue - UnixStart).Ticks / TicksInOneMicrosecond);
}
public static long ToCassandraTimestamp(this DateTimeOffset dt)
{
// we are using the microsecond format from 1/1/1970 00:00:00 UTC same as the Cassandra server
- return (dt - UnixStart).Ticks / 10L;
+ return (dt - UnixStart).Ticks / TicksInOneMicrosecond;
}
public static DateTimeOffset FromCassandraTimestamp(long ts)
{
+ // convert a timestamp in seconds to ticks
+ // ** this should never happen, but it is in here for good measure **
if (ts <= MaxUnixSeconds)
- ts *= 1000L;
+ ts *= TicksInOneSecond;
+ // convert a timestamp in milliseconds to ticks
if (ts <= MaxUnixMilliseconds)
- ts *= 1000L;
+ ts *= TicksInOneMillisecond;
+ // convert a timestamp in microseconds to ticks
if (ts <= MaxUnixMicroseconds)
- ts *= 10L;
+ ts *= TicksInOneMicrosecond;
return UnixStart.AddTicks(ts);
}
Please sign in to comment.
Something went wrong with that request. Please try again.