C# Class Raven.Abstractions.Linq.DateTools

Provides support for converting dates to strings and vice-versa. The strings are structured so that lexicographic sorting orders them by date, which makes them suitable for use as field values and search terms.

This class also helps you to limit the resolution of your dates. Do not save dates with a finer resolution than you really need, as then RangeQuery and PrefixQuery will require more memory and become slower.

Compared to {@link DateField} the strings generated by the methods in this class take slightly more space, unless your selected resolution is set to Resolution.DAY or lower.

Another approach is {@link NumericUtils}, which provides a sortable binary representation (prefix encoded) of numeric values, which date/time are. For indexing a {@link Date} or {@link Calendar}, just get the Unix timestamp as long using {@link Date#getTime} or {@link Calendar#getTimeInMillis} and index this as a numeric value with {@link NumericField} and use {@link NumericRangeQuery} to query it.

ファイルを表示 Open project: robashton/ravendb

Public Methods

Method Description
DateToString ( System date, Resolution resolution ) : System.String

Converts a Date to a string suitable for indexing.

Round ( System date, Resolution resolution ) : System.DateTime

Limit a date's resolution. For example, the date 2004-09-21 13:50:11 will be changed to 2004-09-01 00:00:00 when using Resolution.MONTH.

Round ( long time, Resolution resolution ) : long

Limit a date's resolution. For example, the date 1095767411000 (which represents 2004-09-21 13:50:11) will be changed to 1093989600000 (2004-09-01 00:00:00) when using Resolution.MONTH.

StringToDate ( System dateString ) : System.DateTime

Converts a string produced by timeToString or DateToString back to a time, represented as a Date object.

expected format

StringToTime ( System dateString ) : long

Converts a string produced by timeToString or DateToString back to a time, represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT.

expected format

TimeToString ( long time, Resolution resolution ) : System.String

Converts a millisecond time to a string suitable for indexing.

Private Methods

Method Description
DateTools ( ) : System

Method Details

DateToString() public static method

Converts a Date to a string suitable for indexing.
public static DateToString ( System date, Resolution resolution ) : System.String
date System the date to be converted ///
resolution Resolution the desired resolution, see /// {@link #Round(Date, DateTools.Resolution)} ///
return System.String

Round() public static method

Limit a date's resolution. For example, the date 2004-09-21 13:50:11 will be changed to 2004-09-01 00:00:00 when using Resolution.MONTH.
public static Round ( System date, Resolution resolution ) : System.DateTime
date System The date.
resolution Resolution The desired resolution of the date to be returned
return System.DateTime

Round() public static method

Limit a date's resolution. For example, the date 1095767411000 (which represents 2004-09-21 13:50:11) will be changed to 1093989600000 (2004-09-01 00:00:00) when using Resolution.MONTH.
public static Round ( long time, Resolution resolution ) : long
time long The time in milliseconds (not ticks).
resolution Resolution The desired resolution of the date to be returned ///
return long

StringToDate() public static method

Converts a string produced by timeToString or DateToString back to a time, represented as a Date object. expected format
public static StringToDate ( System dateString ) : System.DateTime
dateString System the date string to be converted ///
return System.DateTime

StringToTime() public static method

Converts a string produced by timeToString or DateToString back to a time, represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT. expected format
public static StringToTime ( System dateString ) : long
dateString System the date string to be converted ///
return long

TimeToString() public static method

Converts a millisecond time to a string suitable for indexing.
public static TimeToString ( long time, Resolution resolution ) : System.String
time long the date expressed as milliseconds since January 1, 1970, 00:00:00 GMT ///
resolution Resolution the desired resolution, see /// {@link #Round(long, DateTools.Resolution)} ///
return System.String