Skip to content

Commit a160f28

Browse files
gligorovjosesimoes
authored andcommitted
Add new TimeSpan.From methods (#57)
1 parent 35f62a9 commit a160f28

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

source/nanoFramework.CoreLibrary/System/TimeSpan.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,42 @@ public double TotalMilliseconds
258258
/// <param name="value">A number of ticks that represent a time.</param>
259259
/// <returns>An object that represents value.</returns>
260260
public static TimeSpan FromTicks(long value) => new TimeSpan(value);
261+
262+
/// <summary>
263+
/// Returns a <see cref="TimeSpan"/> that represents a specified time, where the specification is in units of miliseconds.
264+
/// </summary>
265+
/// <param name="value">A number of miliseconds that represent a time.</param>
266+
/// <returns>An object that represents value.</returns>
267+
public static TimeSpan FromMiliseconds(long value) => new TimeSpan(TimeSpan.TicksPerMillisecond * value);
268+
269+
/// <summary>
270+
/// Returns a <see cref="TimeSpan"/> that represents a specified time, where the specification is in units of seconds.
271+
/// </summary>
272+
/// <param name="value">A number of seconds that represent a time.</param>
273+
/// <returns>An object that represents value.</returns>
274+
public static TimeSpan FromSeconds(long value) => new TimeSpan(TimeSpan.TicksPerSecond * value);
275+
276+
/// <summary>
277+
/// Returns a <see cref="TimeSpan"/> that represents a specified time, where the specification is in units of minute.
278+
/// </summary>
279+
/// <param name="value">A number of minute that represent a time.</param>
280+
/// <returns>An object that represents value.</returns>
281+
public static TimeSpan FromMinutes(long value) => new TimeSpan(TimeSpan.TicksPerMinute * value);
261282

283+
/// <summary>
284+
/// Returns a <see cref="TimeSpan"/> that represents a specified time, where the specification is in units of hours.
285+
/// </summary>
286+
/// <param name="value">A number of hours that represent a time.</param>
287+
/// <returns>An object that represents value.</returns>
288+
public static TimeSpan FromHours(long value) => new TimeSpan(TimeSpan.TicksPerHour * value);
289+
290+
/// <summary>
291+
/// Returns a <see cref="TimeSpan"/> that represents a specified time, where the specification is in units of days.
292+
/// </summary>
293+
/// <param name="value">A number of days that represent a time.</param>
294+
/// <returns>An object that represents value.</returns>
295+
public static TimeSpan FromDays(long value) => new TimeSpan(TimeSpan.TicksPerDay * value);
296+
262297
/// <summary>
263298
/// Converts the value of the current <see cref="TimeSpan"/> object to its equivalent string representation.
264299
/// </summary>

0 commit comments

Comments
 (0)