1212namespace Elastic . Clients . Elasticsearch ;
1313
1414/// <summary>
15- /// Represents a time value
15+ /// Represents a duration value.
1616/// </summary>
17- [ JsonConverter ( typeof ( TimeConverter ) ) ]
18- public sealed class Time : IComparable < Time > , IEquatable < Time > , IUrlParameter
17+ [ JsonConverter ( typeof ( DurationConverter ) ) ]
18+ public sealed class Duration : IComparable < Duration > , IEquatable < Duration > , IUrlParameter
1919{
2020 private const double MicrosecondsInATick = 0.1 ; // 10 ticks = 1 microsecond
2121 private const double MillisecondsInADay = MillisecondsInAnHour * 24 ;
@@ -40,18 +40,18 @@ public sealed class Time : IComparable<Time>, IEquatable<Time>, IUrlParameter
4040
4141 private static readonly double FLOAT_TOLERANCE = 1e-7 ; // less than 1 nanosecond
4242
43- private Time ( int specialFactor , bool specialValue )
43+ private Duration ( int specialFactor , bool specialValue )
4444 {
4545 if ( ! specialValue )
4646 throw new ArgumentException ( "this constructor is only for static TimeValues" ) ;
4747
4848 StaticTimeValue = specialFactor ;
4949 }
5050
51- public Time ( TimeSpan timeSpan )
51+ public Duration ( TimeSpan timeSpan )
5252 : this ( timeSpan . TotalMilliseconds ) { }
5353
54- public Time ( double milliseconds )
54+ public Duration ( double milliseconds )
5555 {
5656 if ( Math . Abs ( milliseconds - - 1 ) < FLOAT_TOLERANCE )
5757 StaticTimeValue = - 1 ;
@@ -61,14 +61,14 @@ public Time(double milliseconds)
6161 Reduce ( milliseconds ) ;
6262 }
6363
64- public Time ( double factor , TimeUnit interval )
64+ public Duration ( double factor , TimeUnit interval )
6565 {
6666 Factor = factor ;
6767 Interval = interval ;
6868 Milliseconds = GetExactMilliseconds ( Factor . Value , Interval . Value ) ;
6969 }
7070
71- public Time ( string timeUnit )
71+ public Duration ( string timeUnit )
7272 {
7373 if ( timeUnit . IsNullOrEmpty ( ) )
7474 throw new ArgumentException ( "Expression string is empty" , nameof ( timeUnit ) ) ;
@@ -85,17 +85,17 @@ public Time(string timeUnit)
8585
8686 public double ? Milliseconds { get ; private set ; }
8787
88- public static Time MinusOne { get ; } = new Time ( - 1 , true ) ;
88+ public static Duration MinusOne { get ; } = new Duration ( - 1 , true ) ;
8989
90- public static Time Zero { get ; } = new Time ( 0 , true ) ;
90+ public static Duration Zero { get ; } = new Duration ( 0 , true ) ;
9191
9292 private int ? StaticTimeValue { get ; }
9393
94- public static implicit operator Time ( TimeSpan span ) => new ( span ) ;
94+ public static implicit operator Duration ( TimeSpan span ) => new ( span ) ;
9595
96- public static implicit operator Time ( double milliseconds ) => new ( milliseconds ) ;
96+ public static implicit operator Duration ( double milliseconds ) => new ( milliseconds ) ;
9797
98- public static implicit operator Time ( string expression ) => new ( expression ) ;
98+ public static implicit operator Duration ( string expression ) => new ( expression ) ;
9999
100100 private void ParseExpression ( string timeUnit )
101101 {
@@ -147,7 +147,7 @@ private void ParseExpression(string timeUnit)
147147 Milliseconds = GetExactMilliseconds ( Factor . Value , Interval . Value ) ;
148148 }
149149
150- public int CompareTo ( Time other )
150+ public int CompareTo ( Duration other )
151151 {
152152 if ( other == null )
153153 return 1 ;
@@ -182,21 +182,21 @@ public int CompareTo(Time other)
182182
183183 private static bool IsIntegerGreaterThanZero ( double d ) => Math . Abs ( d % 1 ) < double . Epsilon ;
184184
185- public static bool operator < ( Time left , Time right ) => left . CompareTo ( right ) < 0 ;
185+ public static bool operator < ( Duration left , Duration right ) => left . CompareTo ( right ) < 0 ;
186186
187- public static bool operator <= ( Time left , Time right ) => left . CompareTo ( right ) < 0 || left . Equals ( right ) ;
187+ public static bool operator <= ( Duration left , Duration right ) => left . CompareTo ( right ) < 0 || left . Equals ( right ) ;
188188
189- public static bool operator > ( Time left , Time right ) => left . CompareTo ( right ) > 0 ;
189+ public static bool operator > ( Duration left , Duration right ) => left . CompareTo ( right ) > 0 ;
190190
191- public static bool operator >= ( Time left , Time right ) => left . CompareTo ( right ) > 0 || left . Equals ( right ) ;
191+ public static bool operator >= ( Duration left , Duration right ) => left . CompareTo ( right ) > 0 || left . Equals ( right ) ;
192192
193- public static bool operator == ( Time left , Time right ) =>
193+ public static bool operator == ( Duration left , Duration right ) =>
194194 ReferenceEquals ( left , null ) ? right is null : left . Equals ( right ) ;
195195
196- public static bool operator != ( Time left , Time right ) => ! ( left == right ) ;
196+ public static bool operator != ( Duration left , Duration right ) => ! ( left == right ) ;
197197
198198 /// <summary>
199- /// Converts this instance of <see cref="Time " /> to an instance of <see cref="TimeSpan" />.
199+ /// Converts this instance of <see cref="Duration " /> to an instance of <see cref="TimeSpan" />.
200200 /// For values in <see cref="TimeUnit.Microseconds" /> and <see cref="TimeUnit.Nanoseconds" />, value will be rounded to
201201 /// the nearest Tick.
202202 /// All other values will be rounded to the nearest Millisecond.
@@ -206,7 +206,7 @@ public int CompareTo(Time other)
206206 /// special time values <see cref="MinusOne" /> and <see cref="Zero" /> do not have a <see cref="TimeSpan" />
207207 /// representation.
208208 /// </para>
209- /// <para>instance of <see cref="Time " /> has no value for <see cref="Interval" /></para>
209+ /// <para>instance of <see cref="Duration " /> has no value for <see cref="Interval" /></para>
210210 /// </exception>
211211 public TimeSpan ToTimeSpan ( )
212212 {
@@ -256,7 +256,7 @@ string IUrlParameter.GetString(ITransportConfiguration config)
256256 return Milliseconds . ToString ( ) ;
257257 }
258258
259- public bool Equals ( Time other )
259+ public bool Equals ( Duration other )
260260 {
261261 if ( ReferenceEquals ( null , other ) )
262262 return false ;
@@ -286,7 +286,7 @@ public override bool Equals(object obj)
286286 if ( obj . GetType ( ) != GetType ( ) )
287287 return false ;
288288
289- return Equals ( ( Time ) obj ) ;
289+ return Equals ( ( Duration ) obj ) ;
290290 }
291291
292292 public override int GetHashCode ( ) => StaticTimeValue . HasValue
@@ -392,33 +392,33 @@ private static string ExponentFormat(double d)
392392 }
393393}
394394
395- internal sealed class TimeConverter : JsonConverter < Time >
395+ internal sealed class DurationConverter : JsonConverter < Duration >
396396{
397- public override Time ? Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
397+ public override Duration ? Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
398398 {
399399 var token = reader . TokenType ;
400400
401401 switch ( token )
402402 {
403403 case JsonTokenType . String :
404- return new Time ( reader . GetString ( ) ) ;
404+ return new Duration ( reader . GetString ( ) ) ;
405405 case JsonTokenType . Number :
406406 var milliseconds = reader . GetInt64 ( ) ;
407407 if ( milliseconds == - 1 )
408- return Time . MinusOne ;
408+ return Duration . MinusOne ;
409409 if ( milliseconds == 0 )
410- return Time . Zero ;
411- return new Time ( milliseconds ) ;
410+ return Duration . Zero ;
411+ return new Duration ( milliseconds ) ;
412412 default :
413413 return null ;
414414 }
415415 }
416416
417- public override void Write ( Utf8JsonWriter writer , Time value , JsonSerializerOptions options )
417+ public override void Write ( Utf8JsonWriter writer , Duration value , JsonSerializerOptions options )
418418 {
419- if ( value == Time . MinusOne )
419+ if ( value == Duration . MinusOne )
420420 writer . WriteNumberValue ( - 1 ) ;
421- else if ( value == Time . Zero )
421+ else if ( value == Duration . Zero )
422422 writer . WriteNumberValue ( 0 ) ;
423423 else if ( value . Factor . HasValue && value . Interval . HasValue )
424424 writer . WriteStringValue ( value . ToString ( ) ) ;
0 commit comments