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

47 lines
796 B
Markdown
Raw 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.
2022-06-11 00:35:48 +00:00
### makeFromYear
2022-06-13 19:10:24 +00:00
(Now `makeDateFromYear`)
2022-06-11 00:35:48 +00:00
```
Date.makeFromYear: (number) => date
```
```js
makeFromYear(2022.32);
```
### 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
2022-06-13 04:19:28 +00:00
makeFromYear(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
2022-06-13 04:19:28 +00:00
makeFromYear(2040) - makeFromYear(2020); // 20 years
makeFromYear(2040) - years(20); // 2020
2022-06-11 00:35:48 +00:00
```