Skip to content

Commit c70d997

Browse files
ez-today:1.0.0 (#1625)
1 parent 29f1c15 commit c70d997

File tree

5 files changed

+217
-0
lines changed

5 files changed

+217
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Carlo Schafflik
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# ez-today
2+
3+
Simply displays the current date with easy to use customization.
4+
5+
## Included languages
6+
7+
German, English, French, Italian, Czech, Portuguese, Slovakian and Polish months can be used out of the box. If you want to use a language that is not included, you can easily add it yourself. This is shown in the customization section below.
8+
9+
## Usage
10+
11+
The usage is very simple, because there is only the `today()` function.
12+
13+
```typ
14+
#import "@preview/ez-today:1.0.0"
15+
16+
// To get the current date use this
17+
#ez-today.today()
18+
```
19+
20+
## Reference
21+
22+
### `today`
23+
24+
Prints the current date with given arguments.
25+
26+
```typ
27+
#let today(
28+
lang: "de",
29+
format: "d. M Y",
30+
custom-months: ()
31+
) = { .. }
32+
```
33+
34+
**Arguments:**
35+
36+
- `lang`: [`str`] — Select one of the included languages (de, en, fr, it, cs, pt).
37+
- `format`: [`str`] — Specify the output format.
38+
- `custom-months`: [`array`] of [`str`] — Use custom names for each month. This array must have 12 entries. If this is used, the `lang` argument does nothing.
39+
40+
## Customization
41+
42+
The default output prints the full current date with German months like this:
43+
44+
```typ
45+
#ez-today.today() // 11. Oktober 2024
46+
```
47+
48+
You can choose one of the included languages with the `lang` argument:
49+
50+
```typ
51+
#ez-today.today(lang: "en") // 11. October 2024
52+
#ez-today.today(lang: "fr") // 11. Octobre 2024
53+
#ez-today.today(lang: "it") // 11. Ottobre 2024
54+
#ez-today.today(lang: "cs") // 11. Října 2024
55+
#ez-today.today(lang: "pt") // 11. Outubro 2024
56+
#ez-today.today(lang: "sk") // 11. Októbra 2024
57+
#ez-today.today(lang: "pl") // 11. Października 2024
58+
```
59+
60+
You can also change the format of the output with the `format` argument. Pass any string you want here, but know that the following characters will be replaced with the following:
61+
62+
- `d` — The current day as a decimal
63+
- `n` — The current month as a decimal (`lang` argument does nothing)
64+
- `m` — The current month as a zero-padded decimal (`lang` argument does nothing)
65+
- `M` — The current month as a string with either the selected language or the custom array
66+
- `y` — The current year as a decimal with the last two numbers
67+
- `Y` — The current year as a decimal
68+
69+
If you want the current date in ISO 8601 format, you can do so by passing `ISO` to the `format` argument.
70+
71+
Here are some examples:
72+
73+
```typ
74+
#ez-today.today(format:"ISO") // 2024-10-11
75+
#ez-today.today(lang: "en", format: "M d Y") // October 11 2024
76+
#ez-today.today(format: "m-d-y") // 10-11-24
77+
#ez-today.today(format: "d/m") // 11/10
78+
#ez-today.today(format: "d.m.Y") // 11.10.2024
79+
```
80+
81+
Use the `custom-months` argument to give each month a custom name. You can add a new language or use short terms for each month.
82+
83+
```typ
84+
// Defining some custom names
85+
#let my-months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
86+
// Get current date with custom names
87+
#ez-today.today(custom-months: my-months, format: "M-y") // Oct-24
88+
```
89+
90+
## Changelog
91+
92+
### 1.0.0
93+
94+
- Added support for Slovakian and Polish language by ShinoYumi
95+
- Added function for ISO 8601 format by ShinoYumi
96+
- Month numbers with only one digit are now zero-padded
97+
98+
### 0.3.0
99+
100+
- Added support for Portuguese language by Me-At-The-Age-Of-Git
101+
102+
### 0.2.0
103+
104+
- Added support for Czech language by ShinoYumi
105+
106+
### 0.1.0
107+
108+
- First release of ez-today
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#import "../ez-today.typ"
2+
3+
// Default output
4+
#ez-today.today()
5+
6+
// Custom format with English months
7+
#ez-today.today(lang: "en", format: "M-d-Y")
8+
9+
// Defining some custom names
10+
#let my-months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
11+
// Get current date with custom names
12+
#ez-today.today(custom-months: my-months, format: "M-y")
13+
14+
// Get the current date in the ISO 8601 format
15+
#ez-today.today(format: "ISO")
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#let get-month(lang, month) = {
2+
let months = ()
3+
4+
if lang == "de" {
5+
months = ("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember")
6+
} else if lang == "en" {
7+
months = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
8+
} else if lang == "fr" {
9+
months = ("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre")
10+
} else if lang == "it" {
11+
months = ("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre")
12+
} else if lang == "cs" {
13+
months = ("Ledna", "Února", "Března", "Dubna", "Května", "Června", "Července", "Srpna", "Září", "Října", "Listopadu", "Prosince")
14+
} else if lang == "pt" {
15+
months = ("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")
16+
} else if lang == "sk" {
17+
months = ("Januára", "Februára", "Marca", "Apríla", "Mája", "Júna", "Júla", "Augusta", "Septembera", "Októbra", "Novembra", "Decembra")
18+
} else if lang == "pl" {
19+
months = ("Stycznia", "Lutego", "Marca", "Kwietnia", "Maja", "Czerwca", "Lipca", "Sierpnia", "Września", "Października", "Listopada", "Grudnia")
20+
} else {
21+
return ""
22+
}
23+
24+
months.at(month - 1)
25+
}
26+
#let today(lang: "de", format: "d. M Y", custom-months: ()) = {
27+
let use-custom = false
28+
if custom-months.len() == 12 {
29+
use-custom = true
30+
}
31+
32+
// Zero-padding the month number
33+
let month-int = datetime.today().month()
34+
let month-int-string = [#month-int]
35+
if month-int <= 9 {
36+
month-int-string = [0] + month-int-string
37+
}
38+
39+
if format == "ISO" {
40+
return [#datetime.today().year()-#month-int-string\-#datetime.today().day()]
41+
}
42+
43+
for f in format {
44+
if f == "d" {
45+
[#datetime.today().day()]
46+
} else if f == "M" {
47+
if use-custom {
48+
[#custom-months.at(datetime.today().month() - 1)]
49+
} else {
50+
[#get-month(lang, datetime.today().month())]
51+
}
52+
} else if f == "n" {
53+
[#datetime.today().month()]
54+
} else if f == "m" {
55+
[#month-int-string]
56+
} else if f == "Y" {
57+
[#datetime.today().year()]
58+
} else if f == "y" {
59+
[#datetime.today().display("[year repr:last_two]")]
60+
} else {
61+
f
62+
}
63+
}
64+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "ez-today"
3+
version = "1.0.0"
4+
entrypoint = "ez-today.typ"
5+
authors = ["Carlo Schafflik"]
6+
license = "MIT"
7+
description = "Simply displays the full current date."
8+
repository = "https://github.com/CarloSchafflik12/typst-ez-today"
9+
exclude = ["./examples"]

0 commit comments

Comments
 (0)