// ------------------------------------------------------------------------------
// 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 Newtonsoft.Json;
using System;
using System.Xml;
///
/// Represents an edm.duration value.
///
[JsonConverter(typeof(DurationConverter))]
public class Duration
{
internal TimeSpan TimeSpan { get; set; }
///
/// Create a Duration object from a TimeSpan.
///
///
public Duration(TimeSpan timeSpan)
{
this.TimeSpan = timeSpan;
}
///
/// Create a Duration object from an ISO8601 duration.
///
/// An ISO8601 duration. http://en.wikipedia.org/wiki/ISO_8601#Durations
public Duration(string duration)
{
// Convert an ISO8601 duration to a TimeSpan.
this.TimeSpan = XmlConvert.ToTimeSpan(duration);
}
///
/// Convert the stored TimeSpan into an ISO8601 duration.
///
/// An ISO8601 duration. For example, PT1M is "period time of 1 minute"
public override string ToString()
{
return XmlConvert.ToString(this.TimeSpan);
}
}
}