@hmcts/opal-frontend-common 0.0.13 → 0.0.14

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.
@@ -183,6 +183,24 @@ class DateService {
183
183
  const now = this.getDateNow().startOf('day');
184
184
  return Math.round(now.diff(inputDate, 'days').days);
185
185
  }
186
+ /**
187
+ * Returns a date range object with 'from' and 'to' properties.
188
+ * @param pastDays - The number of days in the past from today.
189
+ * @param futureDays - The number of days in the future from today.
190
+ * @param format - The format for the date strings (default: 'yyyy-MM-dd').
191
+ * @returns An object containing 'from' and 'to' date strings in the specified format.
192
+ */
193
+ getDateRange(pastDays = 0, futureDays = 0, format = 'yyyy-MM-dd') {
194
+ const dateTo = this.getDateNow().plus({ days: futureDays }).toISODate();
195
+ const dateFrom = this.getDateNow().minus({ days: pastDays }).toISODate();
196
+ if (!dateTo || !dateFrom) {
197
+ throw new Error('Invalid date range');
198
+ }
199
+ return {
200
+ from: this.toFormat(this.getFromIso(dateFrom), format),
201
+ to: this.toFormat(this.getFromIso(dateTo), format),
202
+ };
203
+ }
186
204
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
187
205
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DateService, providedIn: 'root' });
188
206
  }
@@ -1 +1 @@
1
- {"version":3,"file":"hmcts-opal-frontend-common-services-date-service.mjs","sources":["../../../projects/opal-frontend-common/services/date-service/date.service.ts","../../../projects/opal-frontend-common/services/date-service/hmcts-opal-frontend-common-services-date-service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { DateTime, Duration, DurationLikeObject } from 'luxon';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class DateService {\n /**\n * Calculates the difference in minutes between two DateTime objects.\n * @param startDate The start date and time.\n * @param endDate The end date and time.\n * @returns The difference in minutes between the start and end dates.\n */\n public calculateMinutesDifference(startDate: DateTime, endDate: DateTime): number {\n const minuteDifference = endDate.diff(startDate, 'minutes');\n return Math.max(0, Math.ceil(minuteDifference.minutes));\n }\n\n /**\n * Converts milliseconds to minutes.\n * @param milliseconds - The number of milliseconds to convert.\n * @returns The equivalent number of minutes.\n */\n public convertMillisecondsToMinutes(milliseconds: number): number {\n const minutes = Duration.fromMillis(milliseconds).as('minutes');\n return Math.max(0, Math.ceil(minutes));\n }\n\n /**\n * Calculates the age based on the given date of birth.\n * @param dateOfBirth - The date of birth to calculate the age from.\n * @param format - The format of the date of birth. Defaults to 'dd/MM/yyyy'.\n * @returns The calculated age.\n */\n public calculateAge(dateOfBirth: DateTime | string, format: string = 'dd/MM/yyyy'): number {\n const date = typeof dateOfBirth === 'string' ? this.getFromFormat(dateOfBirth, format) : dateOfBirth;\n\n return Math.floor(DateTime.now().diff(date, 'years').years);\n }\n\n /**\n * Checks if a given date is valid.\n * @param dateInput - The date to be checked. It can be a DateTime object, a string, or null.\n * @param format - The format of the date string (default: 'dd/MM/yyyy').\n * @returns A boolean indicating whether the date is valid or not.\n */\n public isValidDate(dateInput: DateTime | string | null, format: string = 'dd/MM/yyyy'): boolean {\n if (dateInput) {\n const date = typeof dateInput === 'string' ? this.getFromFormat(dateInput, format) : dateInput;\n return date.isValid;\n }\n return false;\n }\n\n /**\n * Returns a string representation of a date subtracted by the given duration.\n * @param duration A DurationLikeObject representing the amount of time to subtract from the current date.\n * @returns A string representing the subtracted date in the format specified by the current locale.\n */\n public getPreviousDate(duration: DurationLikeObject): string {\n return DateTime.now().minus(duration).setLocale('en-gb').toLocaleString();\n }\n\n /**\n * Parses a string value into a DateTime object based on the specified format.\n * @param value - The string value to parse.\n * @param format - The format of the string value.\n * @returns A DateTime object representing the parsed value.\n */\n public getFromFormat(value: string, format: string): DateTime<true> | DateTime<false> {\n return DateTime.fromFormat(value, format);\n }\n\n /**\n * Parses a string value into a native JavaScript Date object based on the specified format.\n * @param value - The string value to parse.\n * @param format - The format of the string value.\n * @returns A Date object representing the parsed value, or null if parsing fails.\n */\n public getDateFromFormat(value: string, format: string): Date | null {\n const dateTime = DateTime.fromFormat(value, format);\n return dateTime.isValid ? dateTime.toJSDate() : null;\n }\n\n /**\n * Converts a DateTime value to a formatted string.\n *\n * @param value - The DateTime value to format.\n * @param format - The format string to apply to the DateTime value.\n * @returns The formatted string representation of the DateTime value.\n */\n public toFormat(value: DateTime<true> | DateTime<false>, format: string): string {\n return value.toFormat(format);\n }\n\n /**\n * Converts a given Date object to a formatted string based on the specified format.\n *\n * @param value - The Date object to be formatted.\n * @param format - The string format to apply to the Date object.\n * @returns The formatted date string.\n */\n public toDateStringFormat(value: Date, format: string): string {\n return DateTime.fromJSDate(value).toFormat(format);\n }\n\n /**\n * Converts a string in ISO format to a DateTime object.\n * @param value - The string value in ISO format.\n * @returns A DateTime object representing the given value.\n */\n public getFromIso(value: string): DateTime {\n return DateTime.fromISO(value);\n }\n\n /**\n * Returns the current date and time.\n * @returns {DateTime} The current date and time.\n */\n public getDateNow(): DateTime {\n return DateTime.now();\n }\n\n /**\n * Adds a duration to a given date and returns the result in the specified format.\n * @param date - The date to which the duration will be added.\n * @param years - The number of years to add to the date (default: 0).\n * @param months - The number of months to add to the date (default: 0).\n * @param weeks - The number of weeks to add to the date (default: 0).\n * @param days - The number of days to add to the date (default: 0).\n * @param format - The format in which the resulting date will be returned (default: 'dd/MM/yyyy').\n * @returns The resulting date in the specified format.\n */\n public addDurationToDate(\n date: string,\n years: number = 0,\n months: number = 0,\n weeks: number = 0,\n days: number = 0,\n format: string = 'dd/MM/yyyy',\n ): string {\n const dateObj = this.getFromFormat(date, format);\n const newDate = dateObj.plus({ years, months, weeks, days });\n return newDate.toFormat(format);\n }\n\n /**\n * Calculates the number of days between two dates.\n * @param startDate - The start date in the specified format.\n * @param endDate - The end date in the specified format.\n * @param format - The format of the dates (default: 'dd/MM/yyyy').\n * @returns The number of days between the start and end dates.\n */\n public calculateDaysBetweenDates(startDate: string, endDate: string, format: string = 'dd/MM/yyyy'): number {\n const start = this.getFromFormat(startDate, format);\n const end = this.getFromFormat(endDate, format);\n const diff = end.diff(start, 'days');\n return diff.days;\n }\n\n /**\n * Checks if a given date is in the past.\n * @param date - The date to check.\n * @param format - The format of the date string. Defaults to 'dd/MM/yyyy'.\n * @returns True if the date is in the past, false otherwise.\n */\n public isDateInThePast(date: string, format: string = 'dd/MM/yyyy'): boolean {\n return this.getFromFormat(date, format) < DateTime.now();\n }\n\n /**\n * Checks if a given date is in the future.\n * @param date - The date to check.\n * @param yearsInTheFuture - Optional. The number of years in the future to compare against. If not provided, the current date is used.\n * @param format - Optional. The format of the input date. Defaults to 'dd/MM/yyyy'.\n * @returns True if the date is in the future, false otherwise.\n */\n public isDateInTheFuture(date: string, yearsInTheFuture?: number, format: string = 'dd/MM/yyyy'): boolean {\n const now = DateTime.now();\n const dateValue = this.getFromFormat(date, format);\n\n if (yearsInTheFuture) {\n const futureDate = now.plus({ years: yearsInTheFuture });\n return dateValue > futureDate;\n }\n\n return dateValue > now;\n }\n\n /**\n * Converts a date string from one format to another.\n *\n * @param date - The date string to be converted.\n * @param fromFormat - The format of the input date string.\n * @param toFormat - The desired format of the output date string.\n * @returns The date string in the desired format.\n */\n public getFromFormatToFormat(date: string, fromFormat: string, toFormat: string): string {\n return this.getFromFormat(date, fromFormat).toFormat(toFormat);\n }\n\n /**\n * Calculates the number of days between the current date and a given ISO date string.\n *\n * @param value - An ISO 8601 formatted date string representing the target date.\n * @returns The number of days between the current date and the input date.\n * Returns 0 if the input date is invalid.\n */\n public getDaysAgo(value: string): number {\n const inputDate = this.getFromIso(value).startOf('day');\n\n const now = this.getDateNow().startOf('day');\n return Math.round(now.diff(inputDate, 'days').days);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAMa,WAAW,CAAA;AACtB;;;;;AAKG;IACI,0BAA0B,CAAC,SAAmB,EAAE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C;QAEvD,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;AAC5C,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC;;wGA9M1C,WAAW,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAX,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAW,cAFV,MAAM,EAAA,CAAA;;4FAEP,WAAW,EAAA,UAAA,EAAA,CAAA;kBAHvB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;ACLD;;AAEG;;;;"}
1
+ {"version":3,"file":"hmcts-opal-frontend-common-services-date-service.mjs","sources":["../../../projects/opal-frontend-common/services/date-service/date.service.ts","../../../projects/opal-frontend-common/services/date-service/hmcts-opal-frontend-common-services-date-service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { DateTime, Duration, DurationLikeObject } from 'luxon';\nimport { IDateRange } from './interfaces/date.service.interface';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class DateService {\n /**\n * Calculates the difference in minutes between two DateTime objects.\n * @param startDate The start date and time.\n * @param endDate The end date and time.\n * @returns The difference in minutes between the start and end dates.\n */\n public calculateMinutesDifference(startDate: DateTime, endDate: DateTime): number {\n const minuteDifference = endDate.diff(startDate, 'minutes');\n return Math.max(0, Math.ceil(minuteDifference.minutes));\n }\n\n /**\n * Converts milliseconds to minutes.\n * @param milliseconds - The number of milliseconds to convert.\n * @returns The equivalent number of minutes.\n */\n public convertMillisecondsToMinutes(milliseconds: number): number {\n const minutes = Duration.fromMillis(milliseconds).as('minutes');\n return Math.max(0, Math.ceil(minutes));\n }\n\n /**\n * Calculates the age based on the given date of birth.\n * @param dateOfBirth - The date of birth to calculate the age from.\n * @param format - The format of the date of birth. Defaults to 'dd/MM/yyyy'.\n * @returns The calculated age.\n */\n public calculateAge(dateOfBirth: DateTime | string, format: string = 'dd/MM/yyyy'): number {\n const date = typeof dateOfBirth === 'string' ? this.getFromFormat(dateOfBirth, format) : dateOfBirth;\n\n return Math.floor(DateTime.now().diff(date, 'years').years);\n }\n\n /**\n * Checks if a given date is valid.\n * @param dateInput - The date to be checked. It can be a DateTime object, a string, or null.\n * @param format - The format of the date string (default: 'dd/MM/yyyy').\n * @returns A boolean indicating whether the date is valid or not.\n */\n public isValidDate(dateInput: DateTime | string | null, format: string = 'dd/MM/yyyy'): boolean {\n if (dateInput) {\n const date = typeof dateInput === 'string' ? this.getFromFormat(dateInput, format) : dateInput;\n return date.isValid;\n }\n return false;\n }\n\n /**\n * Returns a string representation of a date subtracted by the given duration.\n * @param duration A DurationLikeObject representing the amount of time to subtract from the current date.\n * @returns A string representing the subtracted date in the format specified by the current locale.\n */\n public getPreviousDate(duration: DurationLikeObject): string {\n return DateTime.now().minus(duration).setLocale('en-gb').toLocaleString();\n }\n\n /**\n * Parses a string value into a DateTime object based on the specified format.\n * @param value - The string value to parse.\n * @param format - The format of the string value.\n * @returns A DateTime object representing the parsed value.\n */\n public getFromFormat(value: string, format: string): DateTime<true> | DateTime<false> {\n return DateTime.fromFormat(value, format);\n }\n\n /**\n * Parses a string value into a native JavaScript Date object based on the specified format.\n * @param value - The string value to parse.\n * @param format - The format of the string value.\n * @returns A Date object representing the parsed value, or null if parsing fails.\n */\n public getDateFromFormat(value: string, format: string): Date | null {\n const dateTime = DateTime.fromFormat(value, format);\n return dateTime.isValid ? dateTime.toJSDate() : null;\n }\n\n /**\n * Converts a DateTime value to a formatted string.\n *\n * @param value - The DateTime value to format.\n * @param format - The format string to apply to the DateTime value.\n * @returns The formatted string representation of the DateTime value.\n */\n public toFormat(value: DateTime<true> | DateTime<false>, format: string): string {\n return value.toFormat(format);\n }\n\n /**\n * Converts a given Date object to a formatted string based on the specified format.\n *\n * @param value - The Date object to be formatted.\n * @param format - The string format to apply to the Date object.\n * @returns The formatted date string.\n */\n public toDateStringFormat(value: Date, format: string): string {\n return DateTime.fromJSDate(value).toFormat(format);\n }\n\n /**\n * Converts a string in ISO format to a DateTime object.\n * @param value - The string value in ISO format.\n * @returns A DateTime object representing the given value.\n */\n public getFromIso(value: string): DateTime {\n return DateTime.fromISO(value);\n }\n\n /**\n * Returns the current date and time.\n * @returns {DateTime} The current date and time.\n */\n public getDateNow(): DateTime {\n return DateTime.now();\n }\n\n /**\n * Adds a duration to a given date and returns the result in the specified format.\n * @param date - The date to which the duration will be added.\n * @param years - The number of years to add to the date (default: 0).\n * @param months - The number of months to add to the date (default: 0).\n * @param weeks - The number of weeks to add to the date (default: 0).\n * @param days - The number of days to add to the date (default: 0).\n * @param format - The format in which the resulting date will be returned (default: 'dd/MM/yyyy').\n * @returns The resulting date in the specified format.\n */\n public addDurationToDate(\n date: string,\n years: number = 0,\n months: number = 0,\n weeks: number = 0,\n days: number = 0,\n format: string = 'dd/MM/yyyy',\n ): string {\n const dateObj = this.getFromFormat(date, format);\n const newDate = dateObj.plus({ years, months, weeks, days });\n return newDate.toFormat(format);\n }\n\n /**\n * Calculates the number of days between two dates.\n * @param startDate - The start date in the specified format.\n * @param endDate - The end date in the specified format.\n * @param format - The format of the dates (default: 'dd/MM/yyyy').\n * @returns The number of days between the start and end dates.\n */\n public calculateDaysBetweenDates(startDate: string, endDate: string, format: string = 'dd/MM/yyyy'): number {\n const start = this.getFromFormat(startDate, format);\n const end = this.getFromFormat(endDate, format);\n const diff = end.diff(start, 'days');\n return diff.days;\n }\n\n /**\n * Checks if a given date is in the past.\n * @param date - The date to check.\n * @param format - The format of the date string. Defaults to 'dd/MM/yyyy'.\n * @returns True if the date is in the past, false otherwise.\n */\n public isDateInThePast(date: string, format: string = 'dd/MM/yyyy'): boolean {\n return this.getFromFormat(date, format) < DateTime.now();\n }\n\n /**\n * Checks if a given date is in the future.\n * @param date - The date to check.\n * @param yearsInTheFuture - Optional. The number of years in the future to compare against. If not provided, the current date is used.\n * @param format - Optional. The format of the input date. Defaults to 'dd/MM/yyyy'.\n * @returns True if the date is in the future, false otherwise.\n */\n public isDateInTheFuture(date: string, yearsInTheFuture?: number, format: string = 'dd/MM/yyyy'): boolean {\n const now = DateTime.now();\n const dateValue = this.getFromFormat(date, format);\n\n if (yearsInTheFuture) {\n const futureDate = now.plus({ years: yearsInTheFuture });\n return dateValue > futureDate;\n }\n\n return dateValue > now;\n }\n\n /**\n * Converts a date string from one format to another.\n *\n * @param date - The date string to be converted.\n * @param fromFormat - The format of the input date string.\n * @param toFormat - The desired format of the output date string.\n * @returns The date string in the desired format.\n */\n public getFromFormatToFormat(date: string, fromFormat: string, toFormat: string): string {\n return this.getFromFormat(date, fromFormat).toFormat(toFormat);\n }\n\n /**\n * Calculates the number of days between the current date and a given ISO date string.\n *\n * @param value - An ISO 8601 formatted date string representing the target date.\n * @returns The number of days between the current date and the input date.\n * Returns 0 if the input date is invalid.\n */\n public getDaysAgo(value: string): number {\n const inputDate = this.getFromIso(value).startOf('day');\n\n const now = this.getDateNow().startOf('day');\n return Math.round(now.diff(inputDate, 'days').days);\n }\n\n /**\n * Returns a date range object with 'from' and 'to' properties.\n * @param pastDays - The number of days in the past from today.\n * @param futureDays - The number of days in the future from today.\n * @param format - The format for the date strings (default: 'yyyy-MM-dd').\n * @returns An object containing 'from' and 'to' date strings in the specified format.\n */\n public getDateRange(pastDays: number = 0, futureDays: number = 0, format: string = 'yyyy-MM-dd'): IDateRange {\n const dateTo = this.getDateNow().plus({ days: futureDays }).toISODate();\n const dateFrom = this.getDateNow().minus({ days: pastDays }).toISODate();\n\n if (!dateTo || !dateFrom) {\n throw new Error('Invalid date range');\n }\n\n return {\n from: this.toFormat(this.getFromIso(dateFrom), format),\n to: this.toFormat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EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAW,cAFV,MAAM,EAAA,CAAA;;4FAEP,WAAW,EAAA,UAAA,EAAA,CAAA;kBAHvB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;ACND;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmcts/opal-frontend-common",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "license": "MIT",
5
5
  "peerDependencies": {
6
6
  "@angular/common": "^18.2.0 || ^19.0.0",
@@ -1,4 +1,5 @@
1
1
  import { DateTime, DurationLikeObject } from 'luxon';
2
+ import { IDateRange } from './interfaces/date.service.interface';
2
3
  import * as i0 from "@angular/core";
3
4
  export declare class DateService {
4
5
  /**
@@ -126,6 +127,14 @@ export declare class DateService {
126
127
  * Returns 0 if the input date is invalid.
127
128
  */
128
129
  getDaysAgo(value: string): number;
130
+ /**
131
+ * Returns a date range object with 'from' and 'to' properties.
132
+ * @param pastDays - The number of days in the past from today.
133
+ * @param futureDays - The number of days in the future from today.
134
+ * @param format - The format for the date strings (default: 'yyyy-MM-dd').
135
+ * @returns An object containing 'from' and 'to' date strings in the specified format.
136
+ */
137
+ getDateRange(pastDays?: number, futureDays?: number, format?: string): IDateRange;
129
138
  static ɵfac: i0.ɵɵFactoryDeclaration<DateService, never>;
130
139
  static ɵprov: i0.ɵɵInjectableDeclaration<DateService>;
131
140
  }
@@ -0,0 +1,4 @@
1
+ export interface IDateRange {
2
+ to: string;
3
+ from: string;
4
+ }