AFTimeRange Structure
- Last UpdatedNov 18, 2025
- 9 minute read
- PI System
- AF SDK 2024 R2
- Developer
This structure represents a time range which is defined by a start time and an end time.
Namespace: OSIsoft.AF.Time
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
[SerializableAttribute] public struct AFTimeRange : IComparable, IComparable<AFTimeRange>, IEquatable<AFTimeRange>, IFormattable
<SerializableAttribute> Public Structure AFTimeRange Implements IComparable, IComparable(Of AFTimeRange), IEquatable(Of AFTimeRange), IFormattable Dim instance As AFTimeRange
[SerializableAttribute] public value class AFTimeRange : IComparable, IComparable<AFTimeRange>, IEquatable<AFTimeRange>, IFormattable
[<SealedAttribute>] [<SerializableAttribute>] type AFTimeRange = struct interface IComparable interface IComparable<AFTimeRange> interface IEquatable<AFTimeRange> interface IFormattable end
The AFTimeRange type exposes the following members.
Constructors
| Name | Description | |
|---|---|---|
| AFTimeRange(String, String) |
Creates a new AFTimeRange object with the specified
string representations of start and end times.
| |
| AFTimeRange(AFTime, AFTime) |
Creates a new AFTimeRange object with the specified
start and end AFTime values.
| |
| AFTimeRange(String, String, IFormatProvider) |
Creates a new AFTimeRange object with the specified
string representations of start and end times using the specified
culture-specific information and formatting style.
|
Properties
| Name | Description | |
|---|---|---|
| EndTime |
The ending time of the time range represented by this object.
| |
| Span |
The amount of time between the start and end times.
| |
| StartTime |
The starting time of the time range represented by this object.
|
Methods
| Name | Description | |
|---|---|---|
| AdjustForSyncTime |
Adjust the time range so that the start time and end time are in sync with the syncTime.
| |
| CompareTo(Object) |
Compares this instance with a specified Object.
| |
| CompareTo(AFTimeRange) |
Compares this instance with a specified AFTimeRange.
| |
| Equals(Object) |
Determines whether the specified Object is equal to the current object.
(Overrides ValueTypeEquals(Object).) | |
| Equals(AFTimeRange) |
Indicates whether the current object is equal to another object of the same type.
| |
| GetHashCode |
Gets the hash code for this instance of the object which is suitable for use in hashing
algorithms and data structures like a hash table.
(Overrides ValueTypeGetHashCode.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| Intersect |
Computes the intersection between this AFTimeRange and another AFTimeRange.
| |
| Parse(String, String, IFormatProvider) |
Converts the specified local date and time string representations of the start and end times
to its AFTimeRange equivalent by using the specified culture-specific formatting
information.
| |
| Parse(String, String, AFTime, IFormatProvider) |
Converts the specified local date and time string representations of the start and end times
to its AFTimeRange equivalent by using the specified reference time and
culture-specific formatting information.
| |
| ToString |
Returns a String that represents the time range in a format that can
be presented to the user.
(Overrides ValueTypeToString.) | |
| ToString(IFormatProvider) |
Returns a String that represents the time range using the specified
culture-specific information that can be presented to the user.
| |
| ToString(String) |
Returns a String that represents the time range using the specified
format that can be presented to the user.
| |
| ToString(String, IFormatProvider) |
Returns a String that represents the time range using the specified
format and culture-specific information that can be presented to the user.
| |
| TryParse(String, String, AFTimeRange) |
Converts the specified local date and time string representations of the start and end times
to its AFTimeRange equivalent by using the CurrentCulture
and returns a value that indicates whether the conversion succeeded.
| |
| TryParse(String, String, AFTime, AFTimeRange) |
Converts the specified local date and time string representations of the start and end times
to its AFTimeRange equivalent by using the specified reference time and returns
a value that indicates whether the conversion succeeded.
| |
| TryParse(String, String, IFormatProvider, AFTimeRange) |
Converts the specified local date and time string representations of the start and end times
to its AFTimeRange equivalent by using the specified culture-specific formatting
information and returns a value that indicates whether the conversion succeeded.
| |
| TryParse(String, String, AFTime, IFormatProvider, AFTimeRange) |
Converts the specified local date and time string representations of the start and end times
to its AFTimeRange equivalent by using the specified reference time and
culture-specific formatting information, and returns a value that indicates whether the
conversion succeeded.
|
Operators
| Name | Description | |
|---|---|---|
| Equality |
The equality operator (==) compares its operands to determine if they are equal.
| |
| GreaterThan |
The greater than relation operator (>) compares its operands to determine
which one is greater than the other.
| |
| GreaterThanOrEqual |
The greater than or equal relation operator (>=) compares its operands to determine
which one is greater than or equal to the other.
| |
| Inequality |
The inequality operator (!=) compares its operands to determine if they are not equal.
| |
| LessThan |
The less than relation operator (<) compares its operands to determine
which one is less than the other.
| |
| LessThanOrEqual |
The less than or equal relation operator (<=) compares its operands to determine
which one is less than or equal to the other.
|
Fields
| Name | Description | |
|---|---|---|
| Empty |
Represents the empty AFTimeRange.
|
Remarks
A time range can be used as a context when getting values with one of the
AFAttribute.GetValue Overload methods. If the
StartTime and EndTime properties are equal,
then this is the same as only specifying a single time as the context.
Examples
// This example shows how to create a dynamic attribute and obtain // the values of an attribute over a specified time range. // Get the Database PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; AFDatabase myDB = myPISystem.Databases.DefaultDatabase; // Create the Attribute AFAttribute myAttribute = new AFAttribute(myDB); myAttribute.Name = "Sinusoid"; myAttribute.Type = typeof(float); myAttribute.DefaultUOM = myPISystem.UOMDatabase.UOMs["m"]; myAttribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem); myAttribute.ConfigString = @"\\%Server%\Sinusoid"; // Set the Time Range AFTimeRange myTimeRange = new AFTimeRange(); myTimeRange.StartTime = new AFTime(DateTime.UtcNow.AddHours(-1)); myTimeRange.EndTime = AFTime.Now; // Display each Value of the Attribute during the Time Range AFValues myValues = myAttribute.GetValues(myTimeRange, 0, null); Console.WriteLine("Number of values = {0}", myValues.Count); foreach (AFValue myValue in myValues) { Console.WriteLine("Annotated = {0}", myValue.Annotated); Console.WriteLine("IsGood = {0}", myValue.IsGood); Console.WriteLine("Questionable = {0}", myValue.Questionable); Console.WriteLine("Substituted = {0}", myValue.Substituted); Console.WriteLine("TimeStamp = {0}", myValue.Timestamp.LocalTime); Console.WriteLine("UOM = {0}", myValue.UOM); Console.WriteLine("Value = {0}", myValue.Value); }
' This example shows how to create a dynamic attribute and obtain ' the values of an attribute over a specified time range. ' Get the Database Dim myPISystems As New PISystems Dim myPISystem As PISystem = myPISystems.DefaultPISystem Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase ' Create the Attribute Dim myAttribute As New AFAttribute(myDB) myAttribute.Name = "Sinusoid" myAttribute.Type = GetType(Double) myAttribute.DefaultUOM = myPISystem.UOMDatabase.UOMs("m") myAttribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem) myAttribute.ConfigString = "\\%Server%\Sinusoid" ' Set the Time Range Dim myTimeRange As New AFTimeRange() myTimeRange.StartTime = New AFTime(DateTime.UtcNow.AddHours(-1)) myTimeRange.EndTime = AFTime.Now ' Display each Value of the Attribute during the Time Range Dim myValues As AFValues = myAttribute.GetValues(myTimeRange, 0, Nothing) Console.WriteLine("Number of values = {0}", myValues.Count) Dim myValue As AFValue For Each myValue In myValues Console.WriteLine("Annotated = {0}", myValue.Annotated) Console.WriteLine("IsGood = {0}", myValue.IsGood) Console.WriteLine("Questionable = {0}", myValue.Questionable) Console.WriteLine("Substituted = {0}", myValue.Substituted) Console.WriteLine("TimeStamp = {0}", myValue.Timestamp.LocalTime) Console.WriteLine("UOM = {0}", myValue.UOM) Console.WriteLine("Value = {0}", myValue.Value) Next myValue
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.