@koobiq/angular-moment-adapter 20.1.0 → 20.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.
@@ -1,9 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken } from '@angular/core';
3
3
  import * as i1 from '@koobiq/components/core';
4
+ import * as _koobiq_date_adapter from '@koobiq/date-adapter';
5
+ import { DateUnit, DurationObjectUnits, DurationUnit } from '@koobiq/date-adapter';
4
6
  import { MomentDateAdapterOptions, MomentDateAdapter as MomentDateAdapter$1 } from '@koobiq/moment-date-adapter';
7
+ import { Moment } from 'moment';
5
8
  import { Observable } from 'rxjs';
6
- import * as _koobiq_date_adapter from '@koobiq/date-adapter';
7
9
 
8
10
  /** Configurable options for {@see MomentDateAdapter}. */
9
11
  type IKbqMomentDateAdapterOptions = MomentDateAdapterOptions;
@@ -14,6 +16,7 @@ declare function KBQ_MOMENT_DATE_ADAPTER_OPTIONS_FACTORY(): IKbqMomentDateAdapte
14
16
  declare class MomentDateAdapter extends MomentDateAdapter$1 {
15
17
  protected readonly options?: IKbqMomentDateAdapterOptions;
16
18
  private localeService;
19
+ private readonly timezoneService;
17
20
  constructor();
18
21
  /** A stream that emits when the locale changes. */
19
22
  get localeChanges(): Observable<any>;
@@ -23,6 +26,29 @@ declare class MomentDateAdapter extends MomentDateAdapter$1 {
23
26
  * @param locale The new locale.
24
27
  */
25
28
  setLocale: (locale: any) => void;
29
+ today(): Moment;
30
+ format(date: Moment, displayFormat: string): string;
31
+ startOf(date: Moment, unit: DateUnit): Moment;
32
+ addCalendarUnits(date: Moment, amountOrDurationLikeObject: number | DurationObjectUnits, unit?: DurationUnit): Moment;
33
+ addCalendarYears(date: Moment, years: number): Moment;
34
+ addCalendarMonths(date: Moment, months: number): Moment;
35
+ addCalendarDays(date: Moment, days: number): Moment;
36
+ deserialize(value: any): Moment | null;
37
+ parse(value: any, parseFormat: string | string[]): Moment | null;
38
+ createDate(year: number, month?: number, date?: number): Moment;
39
+ createDateTime(year: number, month: number, date: number, hours: number, minutes: number, seconds: number, milliseconds: number): Moment;
40
+ /** Whether `value` names a calendar day rather than an instant. */
41
+ private namesWallClock;
42
+ /**
43
+ * Moves a date into the active time zone.
44
+ *
45
+ * Unlike the luxon adapter, the moment one has to do this on the way in: `format()` renders whatever
46
+ * offset the moment itself carries, and the base class builds every date in the host zone.
47
+ *
48
+ * `keepLocalTime` picks between the two meanings a zone change can have - converting an instant
49
+ * (`false`, the default) or reading the same wall-clock components in another zone (`true`).
50
+ */
51
+ private applyTimezone;
26
52
  static ɵfac: i0.ɵɵFactoryDeclaration<MomentDateAdapter, never>;
27
53
  static ɵprov: i0.ɵɵInjectableDeclaration<MomentDateAdapter>;
28
54
  }
@@ -1,9 +1,18 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, inject, Injectable, NgModule } from '@angular/core';
3
- import { KBQ_DATE_LOCALE, KBQ_LOCALE_SERVICE, DateAdapter, KbqLocaleServiceModule, KBQ_DATE_FORMATS } from '@koobiq/components/core';
3
+ import { KBQ_DATE_LOCALE, KBQ_LOCALE_SERVICE, KbqDateTimezoneService, DateAdapter, KbqLocaleServiceModule, KBQ_DATE_FORMATS } from '@koobiq/components/core';
4
4
  import { MomentDateAdapter as MomentDateAdapter$1, MOMENT_DATE_FORMATS } from '@koobiq/moment-date-adapter';
5
5
  import { Subject } from 'rxjs';
6
6
 
7
+ /** An ISO date with no time and no offset: it names a calendar day, not an instant. */
8
+ const DATE_ONLY_ISO_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
9
+ const MINUTES_PER_HOUR = 60;
10
+ /** An offset in minutes as `±HH:mm`, the form moment reads unambiguously. */
11
+ const formatOffset = (minutes) => {
12
+ const magnitude = Math.abs(minutes);
13
+ const pad = (value) => `${Math.floor(value)}`.padStart(2, '0');
14
+ return `${minutes < 0 ? '-' : '+'}${pad(magnitude / MINUTES_PER_HOUR)}:${pad(magnitude % MINUTES_PER_HOUR)}`;
15
+ };
7
16
  /** InjectionToken for moment date adapter to configure options. */
8
17
  const KBQ_MOMENT_DATE_ADAPTER_OPTIONS = new InjectionToken('KBQ_MOMENT_DATE_ADAPTER_OPTIONS', {
9
18
  providedIn: 'root',
@@ -22,6 +31,7 @@ class MomentDateAdapter extends MomentDateAdapter$1 {
22
31
  const options = inject(KBQ_MOMENT_DATE_ADAPTER_OPTIONS, { optional: true }) ?? undefined;
23
32
  super(dateLocale, options);
24
33
  this.localeService = inject(KBQ_LOCALE_SERVICE, { optional: true });
34
+ this.timezoneService = inject(KbqDateTimezoneService);
25
35
  this._localeChanges = new Subject();
26
36
  /**
27
37
  * Sets the locale used for all dates.
@@ -39,26 +49,102 @@ class MomentDateAdapter extends MomentDateAdapter$1 {
39
49
  get localeChanges() {
40
50
  return this._localeChanges;
41
51
  }
42
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: MomentDateAdapter, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
43
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: MomentDateAdapter }); }
52
+ today() {
53
+ return this.applyTimezone(super.today());
54
+ }
55
+ format(date, displayFormat) {
56
+ return super.format(this.applyTimezone(date), displayFormat);
57
+ }
58
+ startOf(date, unit) {
59
+ return this.applyTimezone(super.startOf(date, unit), true);
60
+ }
61
+ addCalendarUnits(date, amountOrDurationLikeObject, unit) {
62
+ return this.applyTimezone(super.addCalendarUnits(date, amountOrDurationLikeObject, unit), true);
63
+ }
64
+ addCalendarYears(date, years) {
65
+ return this.applyTimezone(super.addCalendarYears(date, years), true);
66
+ }
67
+ addCalendarMonths(date, months) {
68
+ return this.applyTimezone(super.addCalendarMonths(date, months), true);
69
+ }
70
+ addCalendarDays(date, days) {
71
+ return this.applyTimezone(super.addCalendarDays(date, days), true);
72
+ }
73
+ deserialize(value) {
74
+ const date = super.deserialize(value);
75
+ if (!date)
76
+ return date;
77
+ return this.applyTimezone(date, this.namesWallClock(value));
78
+ }
79
+ parse(value, parseFormat) {
80
+ const date = super.parse(value, parseFormat);
81
+ if (!date)
82
+ return null;
83
+ // Text parsed against a display format is user input: it names wall-clock components in the active
84
+ // zone. Everything else (ISO text, millis, Date) names an instant and must not be shifted.
85
+ const isUserInput = typeof value === 'string' && !!parseFormat;
86
+ return this.applyTimezone(date, isUserInput || this.namesWallClock(value));
87
+ }
88
+ createDate(year, month, date) {
89
+ // Calendar components name a wall-clock date, so they are kept and only the offset changes.
90
+ // Truncated afterwards because the base builds in the host zone, where the requested midnight may
91
+ // not exist — a DST start at midnight moves it to 01:00 before there is anything to keep.
92
+ return this.applyTimezone(super.createDate(year, month, date), true).startOf('day');
93
+ }
94
+ createDateTime(year, month, date, hours, minutes, seconds, milliseconds) {
95
+ // The base sets the time components after `createDate`, so the offset pinned at midnight can be
96
+ // the wrong one for the resulting wall clock on the day of a transition.
97
+ return this.applyTimezone(super.createDateTime(year, month, date, hours, minutes, seconds, milliseconds), true);
98
+ }
99
+ /** Whether `value` names a calendar day rather than an instant. */
100
+ namesWallClock(value) {
101
+ return typeof value === 'string' && DATE_ONLY_ISO_PATTERN.test(value);
102
+ }
103
+ /**
104
+ * Moves a date into the active time zone.
105
+ *
106
+ * Unlike the luxon adapter, the moment one has to do this on the way in: `format()` renders whatever
107
+ * offset the moment itself carries, and the base class builds every date in the host zone.
108
+ *
109
+ * `keepLocalTime` picks between the two meanings a zone change can have - converting an instant
110
+ * (`false`, the default) or reading the same wall-clock components in another zone (`true`).
111
+ */
112
+ applyTimezone(date, keepLocalTime = false) {
113
+ // The base constructor builds locale data through `createDate()` before the fields of this class
114
+ // exist, so the very first calls run without a service and are left in the host zone.
115
+ const offset = this.timezoneService?.offsetAt(date.valueOf()) ?? null;
116
+ if (offset === null)
117
+ return date;
118
+ // Cloned because moment is mutable and the date may be one the application still holds. The offset
119
+ // goes in as text: moment reads a number below 16 as hours rather than minutes.
120
+ const shifted = date.clone().utcOffset(formatOffset(offset), keepLocalTime);
121
+ if (!keepLocalTime)
122
+ return shifted;
123
+ // Keeping the wall clock moves the instant, which can cross a transition — the offset resolved
124
+ // above then belongs to an instant this date no longer denotes.
125
+ const settled = this.timezoneService?.offsetAt(shifted.valueOf()) ?? null;
126
+ return settled === null || settled === offset ? shifted : shifted.utcOffset(formatOffset(settled), true);
127
+ }
128
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.30", ngImport: i0, type: MomentDateAdapter, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
129
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.30", ngImport: i0, type: MomentDateAdapter }); }
44
130
  }
45
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: MomentDateAdapter, decorators: [{
131
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.30", ngImport: i0, type: MomentDateAdapter, decorators: [{
46
132
  type: Injectable
47
133
  }], ctorParameters: () => [] });
48
134
 
49
135
  const KBQ_MOMENT_DATE_FORMATS = MOMENT_DATE_FORMATS;
50
136
 
51
137
  class MomentDateModule {
52
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: MomentDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
53
- /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.25", ngImport: i0, type: MomentDateModule }); }
54
- /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: MomentDateModule, providers: [
138
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.30", ngImport: i0, type: MomentDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
139
+ /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.30", ngImport: i0, type: MomentDateModule }); }
140
+ /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.30", ngImport: i0, type: MomentDateModule, providers: [
55
141
  {
56
142
  provide: DateAdapter,
57
143
  useClass: MomentDateAdapter
58
144
  }
59
145
  ] }); }
60
146
  }
61
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: MomentDateModule, decorators: [{
147
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.30", ngImport: i0, type: MomentDateModule, decorators: [{
62
148
  type: NgModule,
63
149
  args: [{
64
150
  providers: [
@@ -70,9 +156,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImpo
70
156
  }]
71
157
  }] });
72
158
  class KbqMomentDateModule {
73
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: KbqMomentDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
74
- /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.25", ngImport: i0, type: KbqMomentDateModule, imports: [MomentDateModule, KbqLocaleServiceModule] }); }
75
- /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: KbqMomentDateModule, providers: [
159
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.30", ngImport: i0, type: KbqMomentDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
160
+ /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.30", ngImport: i0, type: KbqMomentDateModule, imports: [MomentDateModule, KbqLocaleServiceModule] }); }
161
+ /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.30", ngImport: i0, type: KbqMomentDateModule, providers: [
76
162
  {
77
163
  // todo после добавления McLocaleServiceModule возможно уже неактуально
78
164
  provide: KBQ_DATE_FORMATS,
@@ -80,7 +166,7 @@ class KbqMomentDateModule {
80
166
  }
81
167
  ], imports: [MomentDateModule, KbqLocaleServiceModule] }); }
82
168
  }
83
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: KbqMomentDateModule, decorators: [{
169
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.30", ngImport: i0, type: KbqMomentDateModule, decorators: [{
84
170
  type: NgModule,
85
171
  args: [{
86
172
  imports: [MomentDateModule, KbqLocaleServiceModule],
@@ -1 +1 @@
1
- {"version":3,"file":"koobiq-angular-moment-adapter-adapter.mjs","sources":["../../../packages/angular-moment-adapter/adapter/moment-date-adapter.ts","../../../packages/angular-moment-adapter/adapter/moment-date-formats.ts","../../../packages/angular-moment-adapter/adapter/index.ts","../../../packages/angular-moment-adapter/adapter/koobiq-angular-moment-adapter-adapter.ts"],"sourcesContent":["import { Injectable, InjectionToken, inject } from '@angular/core';\nimport { KBQ_DATE_LOCALE, KBQ_LOCALE_SERVICE, KbqLocaleService } from '@koobiq/components/core';\nimport { MomentDateAdapter as BaseMomentDateAdapter, MomentDateAdapterOptions } from '@koobiq/moment-date-adapter';\nimport { Observable, Subject } from 'rxjs';\n\n/** Configurable options for {@see MomentDateAdapter}. */\nexport type IKbqMomentDateAdapterOptions = MomentDateAdapterOptions;\n\n/** InjectionToken for moment date adapter to configure options. */\nexport const KBQ_MOMENT_DATE_ADAPTER_OPTIONS = new InjectionToken<IKbqMomentDateAdapterOptions>(\n 'KBQ_MOMENT_DATE_ADAPTER_OPTIONS',\n {\n providedIn: 'root',\n factory: KBQ_MOMENT_DATE_ADAPTER_OPTIONS_FACTORY\n }\n);\n\n/** @docs-private */\nexport function KBQ_MOMENT_DATE_ADAPTER_OPTIONS_FACTORY(): IKbqMomentDateAdapterOptions {\n return {\n useUtc: false,\n findDateFormat: false\n };\n}\n\n@Injectable()\nexport class MomentDateAdapter extends BaseMomentDateAdapter {\n protected readonly options?: IKbqMomentDateAdapterOptions;\n private localeService = inject<KbqLocaleService>(KBQ_LOCALE_SERVICE, { optional: true });\n constructor() {\n const dateLocale = inject(KBQ_DATE_LOCALE, { optional: true })!;\n const options =\n inject<IKbqMomentDateAdapterOptions>(KBQ_MOMENT_DATE_ADAPTER_OPTIONS, { optional: true }) ?? undefined;\n\n super(dateLocale, options);\n this.options = options;\n\n this.setLocale(this.localeService?.id || dateLocale);\n\n this.localeService?.changes.subscribe(this.setLocale);\n }\n\n /** A stream that emits when the locale changes. */\n get localeChanges(): Observable<any> {\n return this._localeChanges;\n }\n\n private _localeChanges = new Subject<void>();\n\n /**\n * Sets the locale used for all dates.\n * @param locale The new locale.\n */\n setLocale = (locale: any) => {\n super.setLocale(locale);\n this._localeChanges.next();\n };\n}\n","import { MOMENT_DATE_FORMATS } from '@koobiq/moment-date-adapter';\n\nexport const KBQ_MOMENT_DATE_FORMATS = MOMENT_DATE_FORMATS;\n","import { NgModule } from '@angular/core';\nimport { DateAdapter, KBQ_DATE_FORMATS, KbqLocaleServiceModule } from '@koobiq/components/core';\nimport { MomentDateAdapter } from './moment-date-adapter';\n\nexport * from './moment-date-adapter';\nexport * from './moment-date-formats';\n\n@NgModule({\n providers: [\n {\n provide: DateAdapter,\n useClass: MomentDateAdapter\n }\n ]\n})\nexport class MomentDateModule {}\n\n@NgModule({\n imports: [MomentDateModule, KbqLocaleServiceModule],\n providers: [\n {\n // todo после добавления McLocaleServiceModule возможно уже неактуально\n provide: KBQ_DATE_FORMATS,\n useValue: null\n }\n ]\n})\nexport class KbqMomentDateModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["BaseMomentDateAdapter"],"mappings":";;;;;;AAQA;MACa,+BAA+B,GAAG,IAAI,cAAc,CAC7D,iCAAiC,EACjC;AACI,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,OAAO,EAAE;AACZ,CAAA;AAGL;SACgB,uCAAuC,GAAA;IACnD,OAAO;AACH,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,cAAc,EAAE;KACnB;AACL;AAGM,MAAO,iBAAkB,SAAQA,mBAAqB,CAAA;AAGxD,IAAA,WAAA,GAAA;AACI,QAAA,MAAM,UAAU,GAAG,MAAM,CAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAE;AAC/D,QAAA,MAAM,OAAO,GACT,MAAM,CAA+B,+BAA+B,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,IAAI,SAAS;AAE1G,QAAA,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC;QANtB,IAAA,CAAA,aAAa,GAAG,MAAM,CAAmB,kBAAkB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAmBhF,QAAA,IAAA,CAAA,cAAc,GAAG,IAAI,OAAO,EAAQ;AAE5C;;;AAGG;AACH,QAAA,IAAA,CAAA,SAAS,GAAG,CAAC,MAAW,KAAI;AACxB,YAAA,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC;AACvB,YAAA,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE;AAC9B,QAAA,CAAC;AArBG,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;QAEtB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,IAAI,UAAU,CAAC;QAEpD,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;IACzD;;AAGA,IAAA,IAAI,aAAa,GAAA;Q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OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,EAAA,SAAA,EARjB;AACP,YAAA;;AAEI,gBAAA,OAAO,EAAE,gBAAgB;AACzB,gBAAA,QAAQ,EAAE;AACb;SACJ,EAAA,OAAA,EAAA,CAPS,gBAAgB,EAAE,sBAAsB,CAAA,EAAA,CAAA,CAAA;;4FASzC,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAV/B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACN,oBAAA,OAAO,EAAE,CAAC,gBAAgB,EAAE,sBAAsB,CAAC;AACnD,oBAAA,SAAS,EAAE;AACP,wBAAA;;AAEI,4BAAA,OAAO,EAAE,gBAAgB;AACzB,4BAAA,QAAQ,EAAE;AACb;AACJ;AACJ,iBAAA;;;AC1BD;;AAEG;;;;"}
1
+ {"version":3,"file":"koobiq-angular-moment-adapter-adapter.mjs","sources":["../../../packages/angular-moment-adapter/adapter/moment-date-adapter.ts","../../../packages/angular-moment-adapter/adapter/moment-date-formats.ts","../../../packages/angular-moment-adapter/adapter/index.ts","../../../packages/angular-moment-adapter/adapter/koobiq-angular-moment-adapter-adapter.ts"],"sourcesContent":["import { Injectable, InjectionToken, inject } from '@angular/core';\nimport { KBQ_DATE_LOCALE, KBQ_LOCALE_SERVICE, KbqDateTimezoneService, KbqLocaleService } from '@koobiq/components/core';\nimport { DateUnit, DurationObjectUnits, DurationUnit } from '@koobiq/date-adapter';\nimport { MomentDateAdapter as BaseMomentDateAdapter, MomentDateAdapterOptions } from '@koobiq/moment-date-adapter';\nimport { Moment } from 'moment';\nimport { Observable, Subject } from 'rxjs';\n\n/** Configurable options for {@see MomentDateAdapter}. */\nexport type IKbqMomentDateAdapterOptions = MomentDateAdapterOptions;\n\n/** An ISO date with no time and no offset: it names a calendar day, not an instant. */\nconst DATE_ONLY_ISO_PATTERN = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nconst MINUTES_PER_HOUR = 60;\n\n/** An offset in minutes as `±HH:mm`, the form moment reads unambiguously. */\nconst formatOffset = (minutes: number): string => {\n const magnitude = Math.abs(minutes);\n const pad = (value: number) => `${Math.floor(value)}`.padStart(2, '0');\n\n return `${minutes < 0 ? '-' : '+'}${pad(magnitude / MINUTES_PER_HOUR)}:${pad(magnitude % MINUTES_PER_HOUR)}`;\n};\n\n/** InjectionToken for moment date adapter to configure options. */\nexport const KBQ_MOMENT_DATE_ADAPTER_OPTIONS = new InjectionToken<IKbqMomentDateAdapterOptions>(\n 'KBQ_MOMENT_DATE_ADAPTER_OPTIONS',\n {\n providedIn: 'root',\n factory: KBQ_MOMENT_DATE_ADAPTER_OPTIONS_FACTORY\n }\n);\n\n/** @docs-private */\nexport function KBQ_MOMENT_DATE_ADAPTER_OPTIONS_FACTORY(): IKbqMomentDateAdapterOptions {\n return {\n useUtc: false,\n findDateFormat: false\n };\n}\n\n@Injectable()\nexport class MomentDateAdapter extends BaseMomentDateAdapter {\n protected readonly options?: IKbqMomentDateAdapterOptions;\n private localeService = inject<KbqLocaleService>(KBQ_LOCALE_SERVICE, { optional: true });\n private readonly timezoneService = inject(KbqDateTimezoneService);\n\n constructor() {\n const dateLocale = inject(KBQ_DATE_LOCALE, { optional: true })!;\n const options =\n inject<IKbqMomentDateAdapterOptions>(KBQ_MOMENT_DATE_ADAPTER_OPTIONS, { optional: true }) ?? undefined;\n\n super(dateLocale, options);\n this.options = options;\n\n this.setLocale(this.localeService?.id || dateLocale);\n\n this.localeService?.changes.subscribe(this.setLocale);\n }\n\n /** A stream that emits when the locale changes. */\n get localeChanges(): Observable<any> {\n return this._localeChanges;\n }\n\n private _localeChanges = new Subject<void>();\n\n /**\n * Sets the locale used for all dates.\n * @param locale The new locale.\n */\n setLocale = (locale: any) => {\n super.setLocale(locale);\n this._localeChanges.next();\n };\n\n override today(): Moment {\n return this.applyTimezone(super.today());\n }\n\n override format(date: Moment, displayFormat: string): string {\n return super.format(this.applyTimezone(date), displayFormat);\n }\n\n override startOf(date: Moment, unit: DateUnit): Moment {\n return this.applyTimezone(super.startOf(date, unit), true);\n }\n\n override addCalendarUnits(\n date: Moment,\n amountOrDurationLikeObject: number | DurationObjectUnits,\n unit?: DurationUnit\n ): Moment {\n return this.applyTimezone(super.addCalendarUnits(date, amountOrDurationLikeObject, unit), true);\n }\n\n override addCalendarYears(date: Moment, years: number): Moment {\n return this.applyTimezone(super.addCalendarYears(date, years), true);\n }\n\n override addCalendarMonths(date: Moment, months: number): Moment {\n return this.applyTimezone(super.addCalendarMonths(date, months), true);\n }\n\n override addCalendarDays(date: Moment, days: number): Moment {\n return this.applyTimezone(super.addCalendarDays(date, days), true);\n }\n\n override deserialize(value: any): Moment | null {\n const date = super.deserialize(value);\n\n if (!date) return date;\n\n return this.applyTimezone(date, this.namesWallClock(value));\n }\n\n override parse(value: any, parseFormat: string | string[]): Moment | null {\n const date = super.parse(value, parseFormat);\n\n if (!date) return null;\n\n // Text parsed against a display format is user input: it names wall-clock components in the active\n // zone. Everything else (ISO text, millis, Date) names an instant and must not be shifted.\n const isUserInput = typeof value === 'string' && !!parseFormat;\n\n return this.applyTimezone(date, isUserInput || this.namesWallClock(value));\n }\n\n override createDate(year: number, month?: number, date?: number): Moment {\n // Calendar components name a wall-clock date, so they are kept and only the offset changes.\n // Truncated afterwards because the base builds in the host zone, where the requested midnight may\n // not exist — a DST start at midnight moves it to 01:00 before there is anything to keep.\n return this.applyTimezone(super.createDate(year, month, date), true).startOf('day');\n }\n\n override createDateTime(\n year: number,\n month: number,\n date: number,\n hours: number,\n minutes: number,\n seconds: number,\n milliseconds: number\n ): Moment {\n // The base sets the time components after `createDate`, so the offset pinned at midnight can be\n // the wrong one for the resulting wall clock on the day of a transition.\n return this.applyTimezone(super.createDateTime(year, month, date, hours, minutes, seconds, milliseconds), true);\n }\n\n /** Whether `value` names a calendar day rather than an instant. */\n private namesWallClock(value: any): boolean {\n return typeof value === 'string' && DATE_ONLY_ISO_PATTERN.test(value);\n }\n\n /**\n * Moves a date into the active time zone.\n *\n * Unlike the luxon adapter, the moment one has to do this on the way in: `format()` renders whatever\n * offset the moment itself carries, and the base class builds every date in the host zone.\n *\n * `keepLocalTime` picks between the two meanings a zone change can have - converting an instant\n * (`false`, the default) or reading the same wall-clock components in another zone (`true`).\n */\n private applyTimezone(date: Moment, keepLocalTime = false): Moment {\n // The base constructor builds locale data through `createDate()` before the fields of this class\n // exist, so the very first calls run without a service and are left in the host zone.\n const offset = this.timezoneService?.offsetAt(date.valueOf()) ?? null;\n\n if (offset === null) return date;\n\n // Cloned because moment is mutable and the date may be one the application still holds. The offset\n // goes in as text: moment reads a number below 16 as hours rather than minutes.\n const shifted = date.clone().utcOffset(formatOffset(offset), keepLocalTime);\n\n if (!keepLocalTime) return shifted;\n\n // Keeping the wall clock moves the instant, which can cross a transition — the offset resolved\n // above then belongs to an instant this date no longer denotes.\n const settled = this.timezoneService?.offsetAt(shifted.valueOf()) ?? null;\n\n return settled === null || settled === offset ? shifted : shifted.utcOffset(formatOffset(settled), true);\n }\n}\n","import { MOMENT_DATE_FORMATS } from '@koobiq/moment-date-adapter';\n\nexport const KBQ_MOMENT_DATE_FORMATS = MOMENT_DATE_FORMATS;\n","import { NgModule } from '@angular/core';\nimport { DateAdapter, KBQ_DATE_FORMATS, KbqLocaleServiceModule } from '@koobiq/components/core';\nimport { MomentDateAdapter } from './moment-date-adapter';\n\nexport * from './moment-date-adapter';\nexport * from './moment-date-formats';\n\n@NgModule({\n providers: [\n {\n provide: DateAdapter,\n useClass: MomentDateAdapter\n }\n ]\n})\nexport class MomentDateModule {}\n\n@NgModule({\n imports: [MomentDateModule, KbqLocaleServiceModule],\n providers: [\n {\n // todo после добавления McLocaleServiceModule возможно уже неактуально\n provide: KBQ_DATE_FORMATS,\n useValue: null\n }\n ]\n})\nexport class KbqMomentDateModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["BaseMomentDateAdapter"],"mappings":";;;;;;AAUA;AACA,MAAM,qBA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EAAA,CAAA;kBAV/B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACN,oBAAA,OAAO,EAAE,CAAC,gBAAgB,EAAE,sBAAsB,CAAC;AACnD,oBAAA,SAAS,EAAE;AACP,wBAAA;;AAEI,4BAAA,OAAO,EAAE,gBAAgB;AACzB,4BAAA,QAAQ,EAAE;AACb;AACJ;AACJ,iBAAA;;;AC1BD;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koobiq/angular-moment-adapter",
3
- "version": "20.1.0",
3
+ "version": "20.3.0",
4
4
  "description": "Koobiq Moment Adapter",
5
5
  "keywords": [
6
6
  "angular",
@@ -14,7 +14,9 @@
14
14
  "license": "MIT",
15
15
  "peerDependencies": {
16
16
  "@koobiq/moment-date-adapter": "^3.1.4",
17
- "@koobiq/components": "20.1.0"
17
+ "@koobiq/date-adapter": "^3.0.0",
18
+ "moment": "^2.24.0",
19
+ "@koobiq/components": "20.3.0"
18
20
  },
19
21
  "dependencies": {
20
22
  "tslib": "^2.6.2"