@loykin/datetime-range 0.0.1 → 0.0.3

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/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import React__default from 'react';
3
- import { D as DatetimeRangeUIAdapter } from './UIAdapterContext-Bm35TZtL.cjs';
4
- export { a as DatetimeRangeProvider, u as useDatetimeRangeUI } from './UIAdapterContext-Bm35TZtL.cjs';
3
+ import { D as DatetimeRangeUIAdapter } from './UIAdapterContext-By3WJ5Ep.cjs';
4
+ export { a as DatetimeRangeProvider, u as useDatetimeRangeUI } from './UIAdapterContext-By3WJ5Ep.cjs';
5
5
  import { DayPicker } from 'react-day-picker';
6
6
  import '@base-ui/react/button';
7
7
  import '@base-ui/react/popover';
@@ -227,6 +227,7 @@ declare function toDisplayString(value: DateTimeRangeValue, options?: {
227
227
  * toUrlString({ type: 'relative', relativeNow: true }) // "now"
228
228
  * toUrlString({ type: 'relative', relativeValue: '5', relativeFormat: 'Minutes ago' }) // "now-5m"
229
229
  * toUrlString({ type: 'absolute', absoluteValue: new Date() }) // "1709654400000"
230
+ * toUrlString({ type: 'absolute' }) // "now" (no date to serialize)
230
231
  */
231
232
  declare function toUrlString(value: DateTimeRangeValue): string;
232
233
  /**
@@ -235,6 +236,7 @@ declare function toUrlString(value: DateTimeRangeValue): string;
235
236
  * fromUrlString("now") // { type: 'relative', relativeNow: true }
236
237
  * fromUrlString("now-5m") // { type: 'relative', relativeValue: '5', relativeFormat: 'Minutes ago' }
237
238
  * fromUrlString("1234567890000") // { type: 'absolute', absoluteValue: Date }
239
+ * fromUrlString("123oops") // { type: 'relative', relativeNow: true } (unparseable input)
238
240
  */
239
241
  declare function fromUrlString(urlString: string): DateTimeRangeValue;
240
242
  /** Creates a relative "now" value. */
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import React__default from 'react';
3
- import { D as DatetimeRangeUIAdapter } from './UIAdapterContext-Bm35TZtL.js';
4
- export { a as DatetimeRangeProvider, u as useDatetimeRangeUI } from './UIAdapterContext-Bm35TZtL.js';
3
+ import { D as DatetimeRangeUIAdapter } from './UIAdapterContext-By3WJ5Ep.js';
4
+ export { a as DatetimeRangeProvider, u as useDatetimeRangeUI } from './UIAdapterContext-By3WJ5Ep.js';
5
5
  import { DayPicker } from 'react-day-picker';
6
6
  import '@base-ui/react/button';
7
7
  import '@base-ui/react/popover';
@@ -227,6 +227,7 @@ declare function toDisplayString(value: DateTimeRangeValue, options?: {
227
227
  * toUrlString({ type: 'relative', relativeNow: true }) // "now"
228
228
  * toUrlString({ type: 'relative', relativeValue: '5', relativeFormat: 'Minutes ago' }) // "now-5m"
229
229
  * toUrlString({ type: 'absolute', absoluteValue: new Date() }) // "1709654400000"
230
+ * toUrlString({ type: 'absolute' }) // "now" (no date to serialize)
230
231
  */
231
232
  declare function toUrlString(value: DateTimeRangeValue): string;
232
233
  /**
@@ -235,6 +236,7 @@ declare function toUrlString(value: DateTimeRangeValue): string;
235
236
  * fromUrlString("now") // { type: 'relative', relativeNow: true }
236
237
  * fromUrlString("now-5m") // { type: 'relative', relativeValue: '5', relativeFormat: 'Minutes ago' }
237
238
  * fromUrlString("1234567890000") // { type: 'absolute', absoluteValue: Date }
239
+ * fromUrlString("123oops") // { type: 'relative', relativeNow: true } (unparseable input)
238
240
  */
239
241
  declare function fromUrlString(urlString: string): DateTimeRangeValue;
240
242
  /** Creates a relative "now" value. */
package/dist/index.js CHANGED
@@ -31,6 +31,11 @@ function Button({
31
31
  className,
32
32
  variant = "default",
33
33
  size = "default",
34
+ // @base-ui/react's own Button/useButton() already defaults type="button" internally on
35
+ // every path this wraps, so this default is redundant today — kept anyway as a fallback
36
+ // that doesn't depend on that undocumented (type isn't part of the public prop types)
37
+ // upstream behavior continuing to hold across base-ui versions.
38
+ type = "button",
34
39
  ...props
35
40
  }) {
36
41
  return /* @__PURE__ */ jsx(
@@ -39,6 +44,7 @@ function Button({
39
44
  "data-slot": "button",
40
45
  "data-variant": variant,
41
46
  "data-size": size,
47
+ type,
42
48
  className: buttonVariants({ variant, size, className: typeof className === "string" ? className : void 0 }),
43
49
  ...props
44
50
  }
@@ -922,17 +928,20 @@ function getSegmentValue(date, key) {
922
928
  return date.getSeconds();
923
929
  }
924
930
  }
931
+ function daysInMonth(year, monthIndex) {
932
+ return new Date(year, monthIndex + 1, 0).getDate();
933
+ }
925
934
  function applySegment(date, key, value) {
926
935
  const d = new Date(date);
927
936
  switch (key) {
928
937
  case "year":
929
- d.setFullYear(value);
938
+ d.setFullYear(value, d.getMonth(), Math.min(d.getDate(), daysInMonth(value, d.getMonth())));
930
939
  break;
931
940
  case "month":
932
- d.setMonth(value - 1);
941
+ d.setMonth(value - 1, Math.min(d.getDate(), daysInMonth(d.getFullYear(), value - 1)));
933
942
  break;
934
943
  case "day":
935
- d.setDate(value);
944
+ d.setDate(Math.min(value, daysInMonth(d.getFullYear(), d.getMonth())));
936
945
  break;
937
946
  case "hour":
938
947
  d.setHours(value);
@@ -1168,8 +1177,9 @@ function toDisplayString(value, options) {
1168
1177
  }
1169
1178
  function toUrlString(value) {
1170
1179
  if (value.type === "absolute") {
1171
- const date = value.absoluteValue instanceof Date ? value.absoluteValue : value.absoluteValue ? new Date(value.absoluteValue) : /* @__PURE__ */ new Date();
1172
- return date.getTime().toString();
1180
+ if (!value.absoluteValue) return "now";
1181
+ const time = new Date(value.absoluteValue).getTime();
1182
+ return Number.isNaN(time) ? "now" : time.toString();
1173
1183
  }
1174
1184
  if (value.relativeNow) return "now";
1175
1185
  if (typeof value.relativeValue === "string" && !value.relativeFormat) {
@@ -1211,8 +1221,10 @@ function fromUrlString(urlString) {
1211
1221
  }
1212
1222
  return { type: "relative", relativeNow: true };
1213
1223
  }
1214
- const timestamp = parseInt(urlString, 10);
1215
- if (!isNaN(timestamp)) return { type: "absolute", absoluteValue: new Date(timestamp) };
1224
+ if (/^-?\d+$/.test(urlString)) {
1225
+ const date = new Date(Number(urlString));
1226
+ if (!Number.isNaN(date.getTime())) return { type: "absolute", absoluteValue: date };
1227
+ }
1216
1228
  return { type: "relative", relativeNow: true };
1217
1229
  }
1218
1230
  function relativeNow() {