scdate 4.1.1 → 4.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/README.md CHANGED
@@ -164,6 +164,11 @@ const totalMinutes = getTimeInMinutes(time1) // Get total minutes since midnight
164
164
 
165
165
  // Time formatting
166
166
  const timeString = get12HourTimeString(time1) // e.g., "2:30 PM"
167
+ const compactTime = getCompact12HourTimeString(time1) // e.g., "2:30pm" (or "2pm" when minutes are zero)
168
+ const compactLabeled = getCompact12HourTimeString(time1, {
169
+ onMidnightText: () => 'Midnight',
170
+ onNoonText: () => 'Noon',
171
+ })
167
172
  const hoursString = get12HoursHoursStringFromTime(time1) // Get hours in 12-hour format (e.g., "2")
168
173
  const minutesString = getMinutesStringFromTime(time1) // Get minutes as 2-digit string (e.g., "30")
169
174
 
@@ -186,6 +191,8 @@ const isPM = isTimePM(time1)
186
191
 
187
192
  - **`get12HoursHoursStringFromTime(time)`**: Returns the hours component in 12-hour format as a string (1-12).
188
193
 
194
+ - **`getCompact12HourTimeString(time, options?)`**: Returns a compact 12-hour string with lowercase `am`/`pm`, no space before the period, and minutes omitted when zero (e.g. `8am`, `11:45pm`). Optional `STimeCompact12HourStringOptions` (`onMidnightText` / `onNoonText`) replace the default for exact `00:00` and `12:00` only.
195
+
189
196
  - **`getMinutesStringFromTime(time)`**: Returns the minutes component as a zero-padded 2-digit string (00-59).
190
197
 
191
198
  ### Timestamp Operations (`STimestamp`)
package/dist/sTime.d.ts CHANGED
@@ -1,4 +1,19 @@
1
1
  import { STime } from './internal/STime.js';
2
+ /**
3
+ * Options for customizing the compact 12-hour time string representation.
4
+ */
5
+ export interface STimeCompact12HourStringOptions {
6
+ /**
7
+ * Called when the time is exactly midnight (00:00). Return value replaces the
8
+ * default `12am` text.
9
+ */
10
+ onMidnightText?: () => string;
11
+ /**
12
+ * Called when the time is exactly noon (12:00). Return value replaces the
13
+ * default `12pm` text.
14
+ */
15
+ onNoonText?: () => string;
16
+ }
2
17
  /**
3
18
  * --- Factory ---
4
19
  */
@@ -67,6 +82,15 @@ export declare const getMinutesStringFromTime: (time: string | STime) => string;
67
82
  * in the HH:MM format.
68
83
  */
69
84
  export declare const get12HourTimeString: (time: string | STime) => string;
85
+ /**
86
+ * Returns a compact 12-hour time string: lowercase `am`/`pm`, no space before
87
+ * the period, and minutes omitted when they are zero (e.g. `8am`, `11:45pm`).
88
+ *
89
+ * @param time The time to format. It can be an STime or a string in the HH:MM
90
+ * format.
91
+ * @param options Optional callbacks for exact midnight and noon.
92
+ */
93
+ export declare const getCompact12HourTimeString: (time: string | STime, options?: STimeCompact12HourStringOptions) => string;
70
94
  /**
71
95
  * Returns the time converted to minutes since midnight.
72
96
  *
package/dist/sTime.js CHANGED
@@ -98,6 +98,27 @@ export const get12HourTimeString = (time) => {
98
98
  const sTimeValue = sTime(time);
99
99
  return `${get12HoursHoursStringFromTime(sTimeValue)}:${getMinutesStringFromTime(sTimeValue)} ${isTimePM(sTimeValue) ? 'PM' : 'AM'}`;
100
100
  };
101
+ /**
102
+ * Returns a compact 12-hour time string: lowercase `am`/`pm`, no space before
103
+ * the period, and minutes omitted when they are zero (e.g. `8am`, `11:45pm`).
104
+ *
105
+ * @param time The time to format. It can be an STime or a string in the HH:MM
106
+ * format.
107
+ * @param options Optional callbacks for exact midnight and noon.
108
+ */
109
+ export const getCompact12HourTimeString = (time, options) => {
110
+ const sTimeValue = sTime(time);
111
+ if (sTimeValue.time === '00:00' && options?.onMidnightText) {
112
+ return options.onMidnightText();
113
+ }
114
+ if (sTimeValue.time === '12:00' && options?.onNoonText) {
115
+ return options.onNoonText();
116
+ }
117
+ const minutes = getMinutesFromTime(sTimeValue);
118
+ const minutesPart = minutes === 0 ? '' : `:${getMinutesStringFromTime(sTimeValue)}`;
119
+ const period = isTimePM(sTimeValue) ? 'pm' : 'am';
120
+ return `${get12HoursHoursStringFromTime(sTimeValue)}${minutesPart}${period}`;
121
+ };
101
122
  /**
102
123
  * Returns the time converted to minutes since midnight.
103
124
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scdate",
3
- "version": "4.1.1",
3
+ "version": "4.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"