Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Midwork on ravendb-806

  • Loading branch information...
commit a925bdaac7d46aea4fc6e9aa38124a593357a11d 1 parent bcb0c64
@ayende ayende authored
View
1  Raven.Abstractions/Default.cs
@@ -26,7 +26,6 @@ public static class Default
};
public static readonly string DateTimeOffsetFormatsToWrite = "o";
- public static readonly string TimeSpanLexicalFormat = @"dddddddd\.hh\:mm\:ss\.fffffff";
public static readonly string DateTimeFormatsToWrite = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffff";
public static readonly JsonConverter[] Converters = new JsonConverter[]
View
6 Raven.Abstractions/Linq/DynamicJsonObject.cs
@@ -213,6 +213,12 @@ public object TransformToValue(RavenJToken jToken)
{
return dateTimeOffset;
}
+ TimeSpan timeSpan;
+ if (TimeSpan.TryParse(s, out timeSpan))
+ {
+ return timeSpan;
+ }
+
}
return value ?? new DynamicNullObject { IsExplicitNull = true };
}
View
17 Raven.Client.Lightweight/Document/AbstractDocumentQuery.cs
@@ -1161,7 +1161,7 @@ private string GetFieldNameForRangeQueries(string fieldName, object start, objec
return fieldName;
var val = (start ?? end);
- var isNumeric = val is int || val is long || val is decimal || val is double || val is float;
+ var isNumeric = val is int || val is long || val is decimal || val is double || val is float || val is TimeSpan;
if (isNumeric && fieldName.EndsWith("_Range") == false)
fieldName = fieldName + "_Range";
@@ -1712,19 +1712,6 @@ private string TransformToEqualValue(WhereParams whereParams)
{
return (bool)whereParams.Value ? "true" : "false";
}
- if (type == typeof (TimeSpan))
- {
- var val = (TimeSpan) whereParams.Value;
- return val.ToString(Default.TimeSpanLexicalFormat);
- }
- if (type == typeof(DateTime))
- {
- var val = (DateTime)whereParams.Value;
- var s = val.ToString(Default.DateTimeFormatsToWrite);
- if(val.Kind == DateTimeKind.Utc)
- s += "Z";
- return s;
- }
if (type == typeof(DateTimeOffset))
{
var val = (DateTimeOffset)whereParams.Value;
@@ -1847,6 +1834,8 @@ private string TransformToRangeValue(WhereParams whereParams)
return NumberUtil.NumberToString((double)(decimal)whereParams.Value);
if (whereParams.Value is double)
return NumberUtil.NumberToString((double)whereParams.Value);
+ if (whereParams.Value is TimeSpan)
+ return NumberUtil.NumberToString(((TimeSpan) whereParams.Value).Ticks);
if (whereParams.Value is float)
return NumberUtil.NumberToString((float)whereParams.Value);
if(whereParams.Value is string)
View
24 Raven.Database/Indexing/AnonymousObjectToLuceneDocumentConverter.cs
@@ -183,14 +183,7 @@ public IEnumerable<AbstractField> CreateFields(string name, object value, Field.
yield break;
}
- if (value is TimeSpan)
- {
- var val = (TimeSpan)value;
- var spanAsString = val.ToString(Default.TimeSpanLexicalFormat);
- yield return CreateFieldWithCaching(name, spanAsString, storage,
- indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED_NO_NORMS));
- }
- else if (value is DateTime)
+ if (value is DateTime)
{
var val = (DateTime)value;
var dateAsString = val.ToString(Default.DateTimeFormatsToWrite);
@@ -272,31 +265,36 @@ public IEnumerable<AbstractField> CreateFields(string name, object value, Field.
numericFieldsCache[cacheKey] = numericField = new NumericField(fieldName, storage, true);
}
- if (value is int)
+ if (value is TimeSpan)
+ {
+ yield return numericField.SetDoubleValue(((TimeSpan)value).Ticks);
+
+ }
+ else if (value is int)
{
if (indexDefinition.GetSortOption(name) == SortOptions.Long)
yield return numericField.SetLongValue((int)value);
else
yield return numericField.SetIntValue((int)value);
}
- if (value is long)
+ else if (value is long)
{
yield return numericField
.SetLongValue((long)value);
}
- if (value is decimal)
+ else if (value is decimal)
{
yield return numericField
.SetDoubleValue((double)(decimal)value);
}
- if (value is float)
+ else if (value is float)
{
if (indexDefinition.GetSortOption(name) == SortOptions.Double)
yield return numericField.SetDoubleValue((float)value);
else
yield return numericField.SetFloatValue((float)value);
}
- if (value is double)
+ else if (value is double)
{
yield return numericField
.SetDoubleValue((double)value);
View
15 Raven.Tryouts/Program.cs
@@ -1,10 +1,23 @@
using System;
+using System.Globalization;
internal class Program
{
private static void Main(string[] args)
{
- Console.WriteLine(TimeSpan.FromHours(1123123).ToString(@"dddddddd\.hh\:mm\:ss\.fffffff"));
+ var timeSpan = TimeSpan.FromMilliseconds(1283123);
+
+ Console.WriteLine(ToLexicographicalString(timeSpan));
+ }
+
+ private static string ToLexicographicalString(TimeSpan timeSpan)
+ {
+ var remainingDays = (long) timeSpan.TotalDays;
+ var totalDays = remainingDays;
+ var sign = timeSpan.Ticks >= 0 ? "p" : "";
+ var totalYears = totalDays/365;
+ totalDays = totalDays%365;
+ return string.Format("{0}-y{1:0,0000}-d{2:000}-{3}", sign, totalYears, totalDays, (timeSpan - TimeSpan.FromDays(remainingDays)).ToString());
}
private static float T(double p0)
Please sign in to comment.
Something went wrong with that request. Please try again.