-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathDuration.cs
More file actions
46 lines (41 loc) · 1.54 KB
/
Duration.cs
File metadata and controls
46 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------
namespace Microsoft.Graph
{
using System;
using System.Xml;
using System.Text.Json.Serialization;
/// <summary>
/// Represents an edm.duration value.
/// </summary>
public class Duration
{
internal TimeSpan TimeSpan { get; set; }
/// <summary>
/// Create a Duration object from a TimeSpan.
/// </summary>
/// <param name="timeSpan"></param>
public Duration(TimeSpan timeSpan)
{
this.TimeSpan = timeSpan;
}
/// <summary>
/// Create a Duration object from an ISO8601 duration.
/// </summary>
/// <param name="duration">An ISO8601 duration. http://en.wikipedia.org/wiki/ISO_8601#Durations </param>
public Duration(string duration)
{
// Convert an ISO8601 duration to a TimeSpan.
this.TimeSpan = XmlConvert.ToTimeSpan(duration);
}
/// <summary>
/// Convert the stored TimeSpan into an ISO8601 duration.
/// </summary>
/// <returns>An ISO8601 duration. For example, PT1M is "period time of 1 minute"</returns>
public override string ToString()
{
return XmlConvert.ToString(this.TimeSpan);
}
}
}