squiggle/packages/website/docs/Api/Date.md

45 lines
767 B
Markdown
Raw Permalink Normal View History

2022-06-11 00:35:48 +00:00
---
sidebar_position: 1
title: Date
---
2022-06-13 04:19:28 +00:00
Squiggle date types are a very simple implementation on [Javascript's Date type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date). It's mainly here for early experimentation. There are more relevant functions for the [Duration](/docs/Api/Duration) type.
### fromYear
2022-06-11 00:35:48 +00:00
```
Date.fromYear: (number) => date
2022-06-11 00:35:48 +00:00
```
```js
Date.fromYear(2022.32);
2022-06-11 00:35:48 +00:00
```
### toString
```
toString: (date) => string
```
2022-06-13 04:19:28 +00:00
### add
2022-06-11 00:35:48 +00:00
```
2022-06-13 04:19:28 +00:00
add: (date, duration) => date
2022-06-11 00:35:48 +00:00
```
```js
Date.fromYear(2022.32) + years(5);
2022-06-11 00:35:48 +00:00
```
2022-06-13 04:19:28 +00:00
### subtract
2022-06-11 00:35:48 +00:00
```
2022-06-13 04:19:28 +00:00
subtract: (date, date) => duration
subtract: (date, duration) => date
2022-06-11 00:35:48 +00:00
```
```js
Date.fromYear(2040) - Date.fromYear(2020); // 20 years
Date.fromYear(2040) - years(20); // 2020
2022-06-11 00:35:48 +00:00
```