> For the complete documentation index, see [llms.txt](https://infinitypbr.gitbook.io/magic-pig-games/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/module-documentation/gametime-and-timeboard/timespan.md).

# TimeSpan

The `TimeSpan` class contains `float` values for in-game seconds, minutes, hours, days, weeks, months, seasons, and years. This is used in a variety of the `GameTime` methods, and can also be saved to isolate specific chunks of time that are important to your project.

Many methods which utilize this concept will allow both a `TimeSpan` object, or a list of floats designating the specific `TimeSpan` to utilize.

```csharp
public float Seconds
public float Minutes
public float Hours
public float Days
public float Months
public float Years
```

{% hint style="info" %}
`TimeSpan` does not track time itself, and does not decrease as time passes.
{% endhint %}

{% hint style="success" %}
`TimeSpan` does not include *Weeks* or *Seasons*, but `Gametime` methods will include those when handling TimeSpan objects and doing date and time calculations.
{% endhint %}

## Create a TimeSpan

```csharp
// Create a new Timespan object for 2 weeks -- Each value is optional, defaults to 0
TimeSpan myTimeSpan = new TimeSpan
{
    Weeks = 2
};

// Create an empty Timespan, then populate it
TimeSpan respawnTime = new TimeSpan();
respawnTime.Years = 1;
respawnTime.Months = 6;
```

## Methods

### Add another TimeSpan

```csharp
public TimeSpan Add(TimeSpan other)

// Example
timeSpan = timeSpan.Add(BonusTime);
```

### Multiply by a multiplier `float` value

```csharp
public TimeSpan Multiply(float multiplier)

// Example
timeSpan = timeSpan.Multiply(0.5f); // Cut the time in half
```

{% hint style="info" %}
Remember that all values in a `TimeSpan` are based on in-game time.
{% endhint %}

## Timespan Methods on `Gametime.cs`

These general methods will return a `TimeSpan` object, which may be saved and used later.

<pre class="language-csharp"><code class="lang-csharp"><strong>// Provides the difference between start and end. May be negative if 
</strong><strong>// start is before end.
</strong>public TimeSpan TimeSpanBetween(float startGameTime, float endGameTime)

// Provides the TimeSpan since one gameTime and another. Will use Now() if gameTime
// is not provided. May return negative if otherGameTime is > gameTime
public TimeSpan TimeSpanSince(float otherGameTime, float gameTime = -1)

// Provides the TimeSpan until one gameTime and another. Will use Now() if gameTime
// is not provided. May return negative if otherGameTime is &#x3C; gameTime
public TimeSpan TimeSpanUntil(float otherGameTime, float gameTime = -1)

// Example
TimeSpan timeSpanUntilNextWinterSolstice = TimeSpanUntil(NextWinterSolsticeGameTime());
</code></pre>

### Convert from TimeSpan

See all the conversion methods on the [**Gametime Properties & Methods**](/magic-pig-games/game-modules-4/module-documentation/gametime-and-timeboard/gametime/properties-and-methods.md) page

```csharp
public float TimespanToGameTime(TimeSpan timeSpan)
public float TimeSpanToRealSeconds(TimeSpan timeSpan)
public float TimeSpanToDatePart(DatePart datePart, TimeSpan timeSpan)
```
