# Expired Rentals

When we query for rentals on a [Subgraph](/developers/querying-renfts-on-chain-data.md), there are various attributes which define the time-variant rental status of a `Renting`. These attributes are: `rentedAt`, `rentDuration` and `expired`; and they are often easily misinterpreted.&#x20;

In this short section, we'll demystify the purpose of these fields.

### Expired Rentals

The `Rental` subgraph data modal possesses an `expired` property. This is used to define when a rental successfully terminated within the agreement of the rental period.

By taking a look through the[ Subgraph Mapping](https://github.com/re-nft/subgraph/blob/15554e16b0a688c66efa1e69982e3a2a1d3e44af/mappings/core.ts#L92) (which indexes high-level representations of all on-chain transactions which took place), we can see that when a rental has been claimed, the `Rental` object is marked as expired.

Conversely, [we can see](https://github.com/re-nft/subgraph/blob/15554e16b0a688c66efa1e69982e3a2a1d3e44af/mappings/core.ts#L50) the `expired` property initialized to `false` when a `Rental` is first initiated.

### Elapsed Rentals

If the current date is greater than the time the asset was rented plus the duration of the rent, the rental period has been exceeded by the renter.

This rental state can be determined programmatically by consulting the appropriate subgraph for the smart contract the rental took place on. Using GraphQL to query a subgraph, we can determine the `rentedAt` and `rentDuration` of a specific `Renting` as follows:

```graphql
{
  renting(id: "2") {
    id
    rentedAt
    rentDuration
    expired
  }
}
```

Upon this request, the subgraph will provide the caller with a `Renting` data model with the specified expiration fields included, for instance:

```json
{
  "data": {
    "renting": {
       "id": "1",
      "rentedAt": "1671617899",
      "rentDuration": "1",
      "expired": false
    }
  }
}
```

Note that there are no on-chain events for an expiration, since this would require an associated transaction.

In this regard, if we need to determine if a rental has expired off-chain, we must compute the time at which a rental expires and compare this against the current time.

Below, we outline an example implementation in TypeScript:

```typescript
const rentedAtInSeconds = Number(renting.rentedAt);
const rentDurationInDays = Number(renting.rentDuration);

const rentedAtMilliseconds = new Date(rentedAtInSeconds * 1000).getTime();
const rentDurationMilliseconds = rentDurationInDays * 24 * 60 * 60 * 1000;

const now = Date.now(); // Current time in milliseconds.

const rentingHasElapsed =
  now > rentedAtMilliseconds + rentDurationMilliseconds;
  
if (rentingHasElapsed)
  doSomethingWithElapsedRenting(renting); // Perform some app-specific handling.

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.renft.io/video-tutorials/expired-rentals.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
