Skip to content

Commit 0e934ea

Browse files
New locale blocks & documentation for Date Format V2 (#582)
1 parent 1077e1f commit 0e934ea

4 files changed

Lines changed: 294 additions & 29 deletions

File tree

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Date Format
2+
3+
Date Format is an extension that lets you create, format, compare, and manipulate dates.
4+
5+
## Blocks
6+
7+
NOTE: The ticket shapes cannot be displayed here, they show up as circular shapes.
8+
9+
### Creation & Format
10+
11+
```scratch
12+
current date::#59c074 reporter
13+
```
14+
15+
Returns the current date.
16+
17+
---
18+
19+
```scratch
20+
new date from [2025-03-12]::#59c074 reporter
21+
```
22+
23+
Creates a date value from a string. Accepts most common date formats (e.g. `2025-03-12`, `March 12 2025`, `12/03/2025`). If the string cannot be parsed, it returns an Invalid date.
24+
25+
---
26+
27+
```scratch
28+
format [date] as [dddd, MMMM D, YYYY]::#59c074 reporter
29+
```
30+
31+
Formats a date using a custom pattern string. Tokens in the pattern are replaced with the corresponding date parts. Unrecognised characters aren't modified.
32+
33+
| Token | Output example | Meaning |
34+
| ------ | -------------- | ------------------------- |
35+
| `YYYY` | `2025` | 4-digit year |
36+
| `YY` | `25` | 2-digit year |
37+
| `MMMM` | `January` | Full month name |
38+
| `MMM` | `Jan` | Short month name |
39+
| `MM` | `01` | Month, zero-padded |
40+
| `M` | `1` | Month, no padding |
41+
| `DD` | `09` | Day of month, zero-padded |
42+
| `D` | `9` | Day of month, no padding |
43+
| `dddd` | `Wednesday` | Full weekday name |
44+
| `ddd` | `Wed` | Short weekday name |
45+
| `HH` | `14` | Hour (24h), zero-padded |
46+
| `H` | `14` | Hour (24h), no padding |
47+
| `hh` | `02` | Hour (12h), zero-padded |
48+
| `h` | `2` | Hour (12h), no padding |
49+
| `mm` | `05` | Minutes, zero-padded |
50+
| `m` | `5` | Minutes, no padding |
51+
| `ss` | `08` | Seconds, zero-padded |
52+
| `s` | `8` | Seconds, no padding |
53+
| `A` | `AM` / `PM` | AM/PM indicator |
54+
| `a` | `am` / `pm` | am/pm indicator |
55+
| `SSS` | `042` | Milliseconds, zero-padded |
56+
| `Z` | `+02:00` | UTC timezone offset |
57+
58+
---
59+
60+
```scratch
61+
format [date] as [short v] locale::#59c074 reporter
62+
```
63+
64+
Formats a date using the active locale.
65+
66+
Examples:
67+
- `short` looks like `Wed, May 20, 2026`
68+
- `long` looks like `Wednesday, May 20, 2026`
69+
70+
---
71+
72+
```scratch
73+
format [date] as [relative v]::#59c074 reporter
74+
```
75+
76+
Formats a date using a special format type.
77+
78+
Examples:
79+
- `relative` looks like `3 days ago` or `in 2 hours`
80+
- `ISO string` looks like `2025-03-12T14:05:00.000Z`
81+
82+
---
83+
84+
### Comparisons
85+
86+
```scratch
87+
is [date] valid?::#59c074 boolean
88+
```
89+
90+
Checks if the date is a valid date value.
91+
92+
---
93+
94+
```scratch
95+
is [date1] [after v] [date2]?::#59c074 boolean
96+
```
97+
98+
Compares two dates based on the chosen operation.
99+
100+
---
101+
102+
```scratch
103+
is [date] [weekend v]?::#59c074 boolean
104+
```
105+
106+
Checks a specific property of a date.
107+
108+
- `weekend` = if the day is Saturday or Sunday
109+
- `weekday` = if the day is Monday through Friday
110+
- `today` = if the date is in the same day as today
111+
- `yesterday` = if the date is in the same day as yesterday
112+
- `tomorrow` = if the day is in the same day as tomorrow
113+
- `first of month` = if the day of the month is 1
114+
- `last of month` = if the day is the last day of its month
115+
- `leap year` = if the year is a leap year
116+
117+
---
118+
119+
### Operators
120+
121+
```scratch
122+
get [days v] between [date1] and [date2]::#59c074 reporter
123+
```
124+
125+
Returns the absolute difference between two dates in the given unit.
126+
127+
---
128+
129+
```scratch
130+
get [year v] of [date]::#59c074 reporter
131+
```
132+
133+
Extracts a component from a date with local time.
134+
135+
| Part | Returns |
136+
| -------------- | ------------------------------ |
137+
| `milliseconds` | 0-999 |
138+
| `seconds` | 0-59 |
139+
| `minutes` | 0-59 |
140+
| `hours` | 0-23 |
141+
| `day (week)` | 0 (Sunday) - 6 (Saturday) |
142+
| `day (month)` | 1-31 |
143+
| `day (year)` | 1-366 |
144+
| `month` | 1-12 |
145+
| `year` | e.g. `2025` |
146+
| `time` | Unix timestamp in milliseconds |
147+
148+
---
149+
150+
```scratch
151+
set [year v] of [date] to [2026]::#59c074 reporter
152+
```
153+
154+
Returns a new date with one component replaced by the given value.
155+
Setting `weekday` shifts the date to the matching day within the same week.
156+
157+
---
158+
159+
```scratch
160+
add [1] [days v] to [date]::#59c074 reporter
161+
```
162+
163+
Returns a new date with the specified amount of time added. Use a negative number to subtract.
164+
165+
---
166+
167+
```scratch
168+
round [date] to nearest [minutes v]::#59c074 reporter
169+
```
170+
171+
Returns a new date rounded to the nearest given unit. For example, rounding `14:08` to `minutes` gives `14:08:00.000`, while rounding to `hours` gives `14:00` or `15:00` depending on which is closer.
172+
173+
---
174+
175+
### Locale
176+
177+
```scratch
178+
set locale to [English (US) v]::#59c074
179+
```
180+
181+
Sets the locale used when formatting dates with the *format as locale* block. The option `browser default` uses whatever language the user's browser is set to. This setting is saved with the project.
182+
183+
---
184+
185+
```scratch
186+
current locale::#59c074 reporter
187+
```
188+
189+
Returns the currently active locale code (e.g. `en-US`), or `default` if none has been set.

src/lib/Documentation/pages.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ import PaintUtils from "./PaintUtils.md?raw";
3737
import Resolution from "./Resolution.md?raw";
3838

3939
// Project Interfaces
40-
4140
import ProjectInterfaces from "./ProjectInterfaces.md?raw";
4241

42+
// Date Format V2
43+
import DateFormatV2 from "./DateFormatV2.md?raw";
44+
4345
export default {
4446
// the key is the path to the docs page
4547
// so you can do "sharkpool-particle-tools" for example
@@ -77,5 +79,7 @@ export default {
7779
"Resolution": Resolution,
7880

7981
// Project Interfaces
80-
"ProjectInterfaces": ProjectInterfaces
82+
"ProjectInterfaces": ProjectInterfaces,
83+
84+
"DateFormatV2": DateFormatV2
8185
};

src/lib/extensions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ export default [
260260
code: "ddededodediamante/dateFormatV2.js",
261261
banner: "ddededodediamante/dateFormat.svg",
262262
creator: "ddededodediamante",
263-
tags: ["customtype", "utility", "small", "data", "time"],
263+
documentation: "DateFormatV2",
264+
tags: ["customtype", "utility", "small", "data", "time", "text"],
264265
isGitHub: true,
265266
},
266267
{

0 commit comments

Comments
 (0)