@autobusal/utilities 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this package are documented here. This project follows [Keep a Changelog](https://keepachangelog.com/) and [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## 1.3.0
6
+
7
+ `getDayParts` — the same short date as `getFormattedShort`, but in its parts.
8
+ One string cannot be shortened by CSS, and the seven-day strip needs to drop
9
+ the month on a narrow screen so seven days fit without a scroller.
10
+
5
11
  ## [1.2.0] - 2026-07-25
6
12
 
7
13
  ### Added
package/date.tsx CHANGED
@@ -27,6 +27,28 @@ export const getFormattedShort = (date: Date, t: TFunction<'generate'>): string
27
27
  return `${ t(display.weekday, { ns: 'common' }) }, ${ display.day } ${ t(display.month, { ns: 'common' }).substring(0, 3) }`;
28
28
  };
29
29
 
30
+ /**
31
+ * The same short date, but in parts.
32
+ *
33
+ * Edited: Ferjolt Ozuni - Date: 2026-08-03
34
+ *
35
+ * getFormattedShort returns one string, so a caller that needs to drop the
36
+ * month on a narrow screen cannot - CSS can hide an element but it cannot
37
+ * shorten a sentence. The seven-day strip needs exactly that: "Sat, 01 Aug"
38
+ * seven times does not fit a phone, "Sat 01" does.
39
+ */
40
+ export const getDayParts = (date: Date, t: TFunction<'generate'>): { weekday: string, day: string, month: string } => {
41
+ const day = date.getDate();
42
+ const month = date.toLocaleString('default', { month: 'long' });
43
+ const weekday = date.toLocaleString('default', { weekday: 'short' });
44
+
45
+ return {
46
+ weekday: t(`data.days.${ weekday.toLowerCase() }`, { ns: 'common' }),
47
+ day: day < 10 ? `0${ day }` : String(day),
48
+ month: t(`data.months.${ month.toLowerCase() }`, { ns: 'common' }).substring(0, 3)
49
+ };
50
+ };
51
+
30
52
  export const differenceYears = (date: Date): number => {
31
53
  const milliseconds = Date.now() - date.getTime();
32
54
 
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { createDate, prepareDate, getFormattedShort, differenceYears, futureDate } from './date';
1
+ import { createDate, prepareDate, getFormattedShort, getDayParts, differenceYears, futureDate } from './date';
2
2
  import { Validate, Display } from './form';
3
3
  import { error, notify, success } from './notify';
4
4
  import { getAllowed, getLanguages, getPayments } from './options';
@@ -18,6 +18,7 @@ export {
18
18
  createDate,
19
19
  prepareDate,
20
20
  getFormattedShort,
21
+ getDayParts,
21
22
  differenceYears,
22
23
  DisplayStatus,
23
24
  futureDate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/utilities",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts",