> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart Duration

A `Duration` in Dart is an immutable class representing a continuous span of time. It measures a relative time interval independent of any specific calendar date, time zone, or clock. Internally, Dart normalizes and stores all `Duration` instances as a single integer value of microseconds.

## Instantiation

The `Duration` constructor accepts named, optional integer arguments. Because the class normalizes the input into a single microsecond integer, arguments can be negative or exceed standard time boundaries (e.g., passing 90 minutes is perfectly valid and evaluates to 1 hour and 30 minutes).

```dart theme={"dark"}
const Duration({
  int days = 0,
  int hours = 0,
  int minutes = 0,
  int seconds = 0,
  int milliseconds = 0,
  int microseconds = 0,
});

// Example instantiation
final exactTime = Duration(days: 2, hours: 14, minutes: 45);
final overflowTime = Duration(minutes: 90); // Normalized to 1 hour, 30 minutes
final negativeTime = Duration(hours: -2);   // Represents a negative span
```

## Property Accessors

`Duration` provides getter properties to extract the time span. These properties return the **total** duration truncated to the requested unit, rather than the isolated component passed to the constructor.

```dart theme={"dark"}
final span = Duration(days: 1, hours: 2);

// Returns the entire span converted to the specified unit
print(span.inDays);          // 1
print(span.inHours);         // 26
print(span.inMinutes);       // 1560
print(span.inSeconds);       // 93600
print(span.inMilliseconds);  // 93600000
print(span.inMicroseconds);  // 93600000000

// Returns true if the total microsecond count is less than zero
print(span.isNegative);      // false
```

## Arithmetic Operators

`Duration` supports operator overloading for standard arithmetic, allowing direct mathematical operations between `Duration` instances or between a `Duration` and a numeric scalar.

```dart theme={"dark"}
final d1 = Duration(hours: 2);
final d2 = Duration(minutes: 30);

// Binary operations with other Durations
final sum = d1 + d2;         // Duration(hours: 2, minutes: 30)
final difference = d1 - d2;  // Duration(hours: 1, minutes: 30)

// Unary negation
final negated = -d1;         // Duration(hours: -2)

// Scalar operations (multiplying/dividing the underlying microseconds)
final scaled = d1 * 2;       // Duration(hours: 4)
final divided = d1 ~/ 3;     // Duration(minutes: 40) - Note: requires integer division (~/)
```

## Relational Operators

Because `Duration` implements `Comparable<Duration>`, instances can be compared using standard relational operators. Comparisons are evaluated based on the underlying microsecond integer.

```dart theme={"dark"}
final d1 = Duration(seconds: 60);
final d2 = Duration(minutes: 1);
final d3 = Duration(seconds: 90);

print(d1 == d2); // true
print(d1 < d3);  // true
print(d3 >= d2); // true
```

## Core Methods

`Duration` exposes utility methods for absolute value conversion and explicit comparison.

```dart theme={"dark"}
final negativeDuration = Duration(seconds: -15);

// Returns a new Duration with a positive microsecond value
final absolute = negativeDuration.abs(); // Duration(seconds: 15)

// Returns an integer indicating sort order (-1, 0, or 1)
final comparison = absolute.compareTo(negativeDuration); // 1
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
