Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFTimeRange Structure

  • Last UpdatedNov 18, 2025
  • 9 minute read
AFTimeRange Structure
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

  NameDescription
Public method
AFTimeRange(String, String)
Creates a new AFTimeRange object with the specified string representations of start and end times.
Public method
AFTimeRange(AFTime, AFTime)
Creates a new AFTimeRange object with the specified start and end AFTime values.
Public method
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

  NameDescription
Public property
EndTime
The ending time of the time range represented by this object.
Public property
Span
The amount of time between the start and end times.
Public property
StartTime
The starting time of the time range represented by this object.

Methods

  NameDescription
Public method
AdjustForSyncTime
Adjust the time range so that the start time and end time are in sync with the syncTime.
Public method
CompareTo(Object)
Compares this instance with a specified Object.
Public method
CompareTo(AFTimeRange)
Compares this instance with a specified AFTimeRange.
Public method
Equals(Object)
Determines whether the specified Object is equal to the current object.
(Overrides ValueTypeEquals(Object).)
Public method
Equals(AFTimeRange)
Indicates whether the current object is equal to another object of the same type.
Public method
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.)
Public method
GetType
Gets the Type of the current instance.
(Inherited from Object.)
Public method
Intersect
Computes the intersection between this AFTimeRange and another AFTimeRange.
Public methodStatic member
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.
Public methodStatic member
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.
Public method
ToString
Returns a String that represents the time range in a format that can be presented to the user.
(Overrides ValueTypeToString.)
Public method
ToString(IFormatProvider)
Returns a String that represents the time range using the specified culture-specific information that can be presented to the user.
Public method
ToString(String)
Returns a String that represents the time range using the specified format that can be presented to the user.
Public method
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.
Public methodStatic member
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.
Public methodStatic member
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.
Public methodStatic member
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.
Public methodStatic member
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

  NameDescription
Public operatorStatic member
Equality
The equality operator (==) compares its operands to determine if they are equal.
Public operatorStatic member
GreaterThan
The greater than relation operator (>) compares its operands to determine which one is greater than the other.
Public operatorStatic member
GreaterThanOrEqual
The greater than or equal relation operator (>=) compares its operands to determine which one is greater than or equal to the other.
Public operatorStatic member
Inequality
The inequality operator (!=) compares its operands to determine if they are not equal.
Public operatorStatic member
LessThan
The less than relation operator (<) compares its operands to determine which one is less than the other.
Public operatorStatic member
LessThanOrEqual
The less than or equal relation operator (<=) compares its operands to determine which one is less than or equal to the other.

Fields

  NameDescription
Public fieldStatic member
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.

Version Information

AFSDK


See Also

TitleResults for “How to create a CRG?”Also Available in