<!--
{
  "documentType" : "article",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/cmtimerange-api",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "CMTimeRange"
}
-->

# CMTimeRange

A structure that represents a range of time.

## Discussion

This document describes the API for creating and manipulating `CMTimeRange` structures.

The system represents a `CMTimeRange` as a non-opaque, mutable structure by using two [`CMTime`](/documentation/CoreMedia/CMTime) values that specify the start time and duration of the range. A time range doesn’t include the end time because you calculate it by adding the duration to the start time.

```objc
// An expression that evaluates to false.
CMTimeRangeContainsTime(range, CMTimeRangeGetEnd(range))
```

Convert `CMTimeRanges` to and from `CFDictionaries` (see <doc://com.apple.documentation/documentation/CoreFoundation/CFDictionary>) using [`CMTimeRangeCopyAsDictionary(_:allocator:)`](/documentation/CoreMedia/CMTimeRangeCopyAsDictionary(_:allocator:)) and [`CMTimeRangeMakeFromDictionary(_:)`](/documentation/CoreMedia/CMTimeRangeMakeFromDictionary(_:)) to use in annotations and various Core Foundation containers.

The epoch in a `CMTime` that represents a duration must be `0`, and the value must be nonnegative. The epoch in a `CMTime` that represents a timestamp can be nonzero, but functions (such as [`CMTimeRangeGetUnion(_:otherRange:)`](/documentation/CoreMedia/CMTimeRangeGetUnion(_:otherRange:))) can only perform operations on ranges whose start fields have the same epoch. `CMTimeRanges` can’t span different epochs.

For information about additional functions for managing dates and times, see <doc://com.apple.documentation/documentation/CoreFoundation/time-utilities>.

## Topics

### Creating Time Ranges

[`func CMTimeRangeMake(start: CMTime, duration: CMTime) -> CMTimeRange`](/documentation/CoreMedia/CMTimeRangeMake(start:duration:))

Creates a valid time range with a start time and duration.

[`func CMTimeRangeMakeFromDictionary(CFDictionary) -> CMTimeRange`](/documentation/CoreMedia/CMTimeRangeMakeFromDictionary(_:))

Creates a time range from a dictionary representation of its fields.

[`func CMTimeRangeFromTimeToTime(start: CMTime, end: CMTime) -> CMTimeRange`](/documentation/CoreMedia/CMTimeRangeFromTimeToTime(start:end:))

Creates a valid time range from a start and end time.

### Comparing Time Ranges

[`func CMTimeRangeEqual(CMTimeRange, CMTimeRange) -> Bool`](/documentation/CoreMedia/CMTimeRangeEqual(_:_:))

Returns a Boolean value that indicates whether two time ranges are equal.

[`func CMTimeRangeContainsTime(CMTimeRange, time: CMTime) -> Bool`](/documentation/CoreMedia/CMTimeRangeContainsTime(_:time:))

Returns a Boolean value that indicates whether a time range contains a time.

[`func CMTimeRangeContainsTimeRange(CMTimeRange, otherRange: CMTimeRange) -> Bool`](/documentation/CoreMedia/CMTimeRangeContainsTimeRange(_:otherRange:))

Returns a Boolean value that indicates whether a time range contains another time range.

### Inspecting Time Ranges

[`func CMTIMERANGE_IS_EMPTY(CMTimeRange) -> Bool`](/documentation/CoreMedia/CMTIMERANGE_IS_EMPTY(_:))

Returns a Boolean value that indicates whether a time range has a duration of zero.

[`func CMTIMERANGE_IS_INDEFINITE(CMTimeRange) -> Bool`](/documentation/CoreMedia/CMTIMERANGE_IS_INDEFINITE(_:))

Returns a Boolean value that indicates whether a time range is indefinite.

[`func CMTIMERANGE_IS_INVALID(CMTimeRange) -> Bool`](/documentation/CoreMedia/CMTIMERANGE_IS_INVALID(_:))

Returns a Boolean value that indicates whether a time range is invalid.

[`func CMTIMERANGE_IS_VALID(CMTimeRange) -> Bool`](/documentation/CoreMedia/CMTIMERANGE_IS_VALID(_:))

Returns a Boolean value that indicates whether a time range is valid.

[`#define CMTIMERANGE_IS_EMPTY(range)`](/documentation/CoreMedia/CMTIMERANGE_IS_EMPTY)

Returns a Boolean value that indicates whether a time range has a duration of zero.

[`#define CMTIMERANGE_IS_INDEFINITE(range)`](/documentation/CoreMedia/CMTIMERANGE_IS_INDEFINITE)

Returns a Boolean value that indicates whether a time range is indefinite.

[`#define CMTIMERANGE_IS_INVALID(range)`](/documentation/CoreMedia/CMTIMERANGE_IS_INVALID)

Returns a Boolean value that indicates whether a time range is invalid.

[`#define CMTIMERANGE_IS_VALID(range)`](/documentation/CoreMedia/CMTIMERANGE_IS_VALID)

Returns a Boolean value that indicates whether a time range is valid.

[`func CMTimeRangeGetEnd(CMTimeRange) -> CMTime`](/documentation/CoreMedia/CMTimeRangeGetEnd(_:))

Returns a time value that represents the end of a time range.

[`func CMTimeRangeGetIntersection(CMTimeRange, otherRange: CMTimeRange) -> CMTimeRange`](/documentation/CoreMedia/CMTimeRangeGetIntersection(_:otherRange:))

Returns a new time range with the time elements that are common between the input.

[`func CMTimeRangeGetUnion(CMTimeRange, otherRange: CMTimeRange) -> CMTimeRange`](/documentation/CoreMedia/CMTimeRangeGetUnion(_:otherRange:))

Returns a new time range with the time elements of the input.

### Utility Functions

[`func CMTimeClampToRange(CMTime, range: CMTimeRange) -> CMTime`](/documentation/CoreMedia/CMTimeClampToRange(_:range:))

Returns the nearest time value inside the time range.

[`func CMTimeMapDurationFromRangeToRange(CMTime, fromRange: CMTimeRange, toRange: CMTimeRange) -> CMTime`](/documentation/CoreMedia/CMTimeMapDurationFromRangeToRange(_:fromRange:toRange:))

Translates a duration through a mapping from two time ranges.

[`func CMTimeMapTimeFromRangeToRange(CMTime, fromRange: CMTimeRange, toRange: CMTimeRange) -> CMTime`](/documentation/CoreMedia/CMTimeMapTimeFromRangeToRange(_:fromRange:toRange:))

Translates a time through a mapping from two time ranges.

[`func CMTimeRangeCopyAsDictionary(CMTimeRange, allocator: CFAllocator?) -> CFDictionary?`](/documentation/CoreMedia/CMTimeRangeCopyAsDictionary(_:allocator:))

Returns a dictionary representation of a time range.

[`func CMTimeRangeCopyDescription(allocator: CFAllocator?, range: CMTimeRange) -> CFString?`](/documentation/CoreMedia/CMTimeRangeCopyDescription(allocator:range:))

Returns a string with a description of a time range.

[`func CMTimeRangeShow(CMTimeRange)`](/documentation/CoreMedia/CMTimeRangeShow(_:))

Prints a description of the time range to standard error.

### Data Types

[`struct CMTimeRange`](/documentation/CoreMedia/CMTimeRange)

A structure that represents a time range.

### Constants

[Dictionary Keys](/documentation/CoreMedia/cmtimerange-dictionary-keys)

Keys to use when working with dictionary representations of a time range.

[Pre-Specified Time Ranges](/documentation/CoreMedia/pre-specified-time-ranges)

Constants that specify zero and invalid time ranges.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)