mapa-library-ui 1.3.0 → 1.4.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.
@@ -12,7 +12,7 @@ import * as i1$1 from '@angular/material/input';
12
12
  import { MatInputModule } from '@angular/material/input';
13
13
  import { NgxMaskDirective, provideNgxMask } from 'ngx-mask';
14
14
  import { toObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
15
- import { getMapaUiTexts } from 'mapa-frontend-i18n';
15
+ import { getMapaUiTexts, getIntlLocale, getStoredAppLanguage } from 'mapa-frontend-i18n';
16
16
  import { fromEvent, ReplaySubject } from 'rxjs';
17
17
  import * as i3$1 from '@angular/material/radio';
18
18
  import { MatRadioModule } from '@angular/material/radio';
@@ -537,6 +537,9 @@ const DAY_MONTH_YEAR_PATTERN = /^(\d{2})\/(\d{2})\/(\d{4})$/;
537
537
  function isValidDate(date) {
538
538
  return !Number.isNaN(date.getTime());
539
539
  }
540
+ function buildUtcDate(date, dayOffset, hours, minutes, seconds, milliseconds) {
541
+ return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() + dayOffset, hours, minutes, seconds, milliseconds));
542
+ }
540
543
  function formatDateAsDayMonthYear(date) {
541
544
  const day = `${date.getDate()}`.padStart(2, "0");
542
545
  const month = `${date.getMonth() + 1}`.padStart(2, "0");
@@ -558,18 +561,11 @@ function parseDateValue(value) {
558
561
  if (!trimmedValue) {
559
562
  return null;
560
563
  }
561
- const dayMonthYearMatch = DAY_MONTH_YEAR_PATTERN.exec(trimmedValue);
562
- if (dayMonthYearMatch) {
563
- const [, dayValue, monthValue, yearValue] = dayMonthYearMatch;
564
- const day = Number(dayValue);
565
- const month = Number(monthValue);
566
- const year = Number(yearValue);
567
- const parsedDate = new Date(year, month - 1, day);
568
- if (parsedDate.getFullYear() === year &&
569
- parsedDate.getMonth() === month - 1 &&
570
- parsedDate.getDate() === day) {
571
- return parsedDate;
572
- }
564
+ const brazilianDate = parseBrazilianDate(trimmedValue);
565
+ if (brazilianDate) {
566
+ return brazilianDate;
567
+ }
568
+ if (DAY_MONTH_YEAR_PATTERN.test(trimmedValue)) {
573
569
  return null;
574
570
  }
575
571
  const parsedDate = new Date(trimmedValue);
@@ -578,6 +574,62 @@ function parseDateValue(value) {
578
574
  function isDateValue(value) {
579
575
  return parseDateValue(value) !== null;
580
576
  }
577
+ function parseBrazilianDate(value) {
578
+ const match = DAY_MONTH_YEAR_PATTERN.exec(value.trim());
579
+ if (!match) {
580
+ return null;
581
+ }
582
+ const [, dayValue, monthValue, yearValue] = match;
583
+ const day = Number(dayValue);
584
+ const month = Number(monthValue);
585
+ const year = Number(yearValue);
586
+ const parsedDate = new Date(year, month - 1, day);
587
+ if (parsedDate.getFullYear() !== year ||
588
+ parsedDate.getMonth() !== month - 1 ||
589
+ parsedDate.getDate() !== day) {
590
+ return null;
591
+ }
592
+ return parsedDate;
593
+ }
594
+ function normalizeDateInput(value) {
595
+ return parseDateValue(value);
596
+ }
597
+ function formatBrazilianDate(value) {
598
+ const date = normalizeDateInput(value);
599
+ return date ? formatDateAsDayMonthYear(date) : "";
600
+ }
601
+ function addDays(date, days) {
602
+ const nextDate = new Date(date);
603
+ nextDate.setDate(nextDate.getDate() + days);
604
+ return nextDate;
605
+ }
606
+ function formatLocaleDate(value, dateStyle = "short") {
607
+ const date = normalizeDateInput(value);
608
+ if (!date) {
609
+ return "";
610
+ }
611
+ return new Intl.DateTimeFormat(getIntlLocale(getStoredAppLanguage()), {
612
+ dateStyle,
613
+ }).format(date);
614
+ }
615
+ function formatLocaleDateTime(value, options = {}) {
616
+ const date = normalizeDateInput(value);
617
+ if (!date) {
618
+ return "";
619
+ }
620
+ const { dateStyle = "short", timeStyle = "short" } = options;
621
+ return new Intl.DateTimeFormat(getIntlLocale(getStoredAppLanguage()), {
622
+ dateStyle,
623
+ timeStyle,
624
+ }).format(date);
625
+ }
626
+ function getDefaultDateRange(days = 60) {
627
+ const today = new Date();
628
+ return {
629
+ startDate: formatBrazilianDate(addDays(today, -days)),
630
+ endDate: formatBrazilianDate(today),
631
+ };
632
+ }
581
633
  function getRelativeDateRange(daysBack) {
582
634
  const endDate = new Date();
583
635
  endDate.setHours(23, 59, 59, 999);
@@ -586,6 +638,18 @@ function getRelativeDateRange(daysBack) {
586
638
  startDate.setDate(startDate.getDate() - daysBack);
587
639
  return { startDate, endDate };
588
640
  }
641
+ function toUtcRangeStartIso(value) {
642
+ const date = normalizeDateInput(value);
643
+ return date ? buildUtcDate(date, 0, 3, 0, 0, 0).toISOString() : undefined;
644
+ }
645
+ function toUtcRangeEndIso(value) {
646
+ const date = normalizeDateInput(value);
647
+ return date ? buildUtcDate(date, 1, 2, 59, 59, 999).toISOString() : undefined;
648
+ }
649
+ function toUtcDayExclusiveEndIso(value) {
650
+ const date = normalizeDateInput(value);
651
+ return date ? buildUtcDate(date, 1, 3, 0, 0, 0).toISOString() : undefined;
652
+ }
589
653
 
590
654
  const MAPA_DATEPICKER_FORMATS = {
591
655
  parse: {