Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): added duration example to the wing by example docs #7215

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/by-example/37-duration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Duration
id: duration
slug: /duration
sidebar_label: Duration
description: Get duration of time in Wing
keywords: [Wing language, Type reflection]
image: /img/wing-by-example.png
custom_edit_url: https://github.com/winglang/wing/blob/main/docs/by-example/37-duration.md
---

The [duration](/docs/api/standard-library/std/duration) represents a length of time in Wing.

You can use this to get durations representing the amount of milliseconds, seconds, minutes, hours, days, and years.

```js playground example title="main.w"
let msInHour = duration.fromHours(1).milliseconds;
let msInSeconds = duration.fromSeconds(30).milliseconds;
let secondsInDay = duration.fromDays(1).seconds;
let hoursInDay = duration.fromDays(1).hours;
let hoursInMonth = duration.fromMonths(1).hours;
let daysInYear = duration.fromYears(1).days;

let durations = {
msInHour,
msInSeconds,
secondsInDay,
hoursInDay,
hoursInMonth,
daysInYear
};

log(Json.stringify(durations));
```

```bash title="Wing console output"
# Run locally with wing console
{"msInHour":3600000,"msInSeconds":30000,"secondsInDay":86400,"hoursInDay":24,"hoursInMonth":730,"daysInYear":365}
```