@ptsecurity/mosaic 13.8.4 → 13.9.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.
@@ -931,13 +931,13 @@ class DateFormatter {
931
931
  * @param datetime - should time be shown as well
932
932
  * @param seconds - should time with seconds be shown as well
933
933
  * @param milliseconds - should time with milliseconds be shown as well
934
- * @returns absolute date in common format
934
+ * @param currYear - should current year be shown as well
935
935
  */
936
- absoluteDate(date, params, datetime = false, seconds = false, milliseconds = false) {
936
+ absoluteDate(date, params, datetime = false, seconds = false, milliseconds = false, currYear = false) {
937
937
  if (!this.adapter.isDateInstance(date)) {
938
938
  throw new Error(this.invalidDateErrorText);
939
939
  }
940
- const variables = this.compileVariables(date, { ...this.adapter.config.variables, ...params.variables });
940
+ const variables = this.compileVariables(date, { ...this.adapter.config.variables, ...params.variables }, currYear);
941
941
  variables.SHOW_SECONDS = seconds ? 'yes' : 'no';
942
942
  variables.SHOW_MILLISECONDS = milliseconds ? 'yes' : 'no';
943
943
  const template = datetime ? params.DATETIME : params.DATE;
@@ -945,10 +945,11 @@ class DateFormatter {
945
945
  }
946
946
  /**
947
947
  * @param date - date
948
+ * @param currYear - should the year be shown forced
948
949
  * @returns absolute date in short format
949
950
  */
950
- absoluteShortDate(date) {
951
- return this.absoluteDate(date, this.config.absoluteTemplates.short);
951
+ absoluteShortDate(date, currYear = false) {
952
+ return this.absoluteDate(date, this.config.absoluteTemplates.short, false, false, false, currYear);
952
953
  }
953
954
  /**
954
955
  * @param date - date
@@ -956,14 +957,15 @@ class DateFormatter {
956
957
  * @returns absolute date in short format with time
957
958
  */
958
959
  absoluteShortDateTime(date, options) {
959
- return this.absoluteDate(date, this.config.absoluteTemplates.short, true, options?.seconds, options?.milliseconds);
960
+ return this.absoluteDate(date, this.config.absoluteTemplates.short, true, options?.seconds, options?.milliseconds, options?.currYear);
960
961
  }
961
962
  /**
962
963
  * @param date - date
964
+ * @param currYear - should the year be shown forced
963
965
  * @returns absolute date in long format
964
966
  */
965
- absoluteLongDate(date) {
966
- return this.absoluteDate(date, this.config.absoluteTemplates.long);
967
+ absoluteLongDate(date, currYear = false) {
968
+ return this.absoluteDate(date, this.config.absoluteTemplates.long, false, false, false, currYear);
967
969
  }
968
970
  /**
969
971
  * @param date - date
@@ -971,7 +973,7 @@ class DateFormatter {
971
973
  * @returns absolute date in long format with time
972
974
  */
973
975
  absoluteLongDateTime(date, options) {
974
- return this.absoluteDate(date, this.config.absoluteTemplates.long, true, options?.seconds, options?.milliseconds);
976
+ return this.absoluteDate(date, this.config.absoluteTemplates.long, true, options?.seconds, options?.milliseconds, options?.currYear);
975
977
  }
976
978
  /**
977
979
  * @param startDate - start date
@@ -1160,7 +1162,13 @@ class DateFormatter {
1160
1162
  rangeMiddleDateTime(startDate, endDate, options) {
1161
1163
  return this.rangeDateTime(startDate, endDate, this.config.rangeTemplates.closedRange.middle, options?.seconds, options?.milliseconds);
1162
1164
  }
1163
- compileVariables(date, variables) {
1165
+ /**
1166
+ * @param date
1167
+ * @param variables - date template variables
1168
+ * @param currYearForced - param for absolute days formatting
1169
+ * @private
1170
+ */
1171
+ compileVariables(date, variables, currYearForced = false) {
1164
1172
  const compiledVariables = {};
1165
1173
  // tslint:disable-next-line:no-for-in
1166
1174
  for (const key in variables) {
@@ -1170,22 +1178,20 @@ class DateFormatter {
1170
1178
  const value = variables[key];
1171
1179
  compiledVariables[key] = this.adapter.format(date, value);
1172
1180
  }
1173
- compiledVariables.CURRENT_YEAR = this.hasSame(date, this.adapter.today(), 'year');
1181
+ compiledVariables.CURRENT_YEAR = (currYearForced && 'no') || this.hasSame(date, this.adapter.today(), 'year');
1174
1182
  return compiledVariables;
1175
1183
  }
1176
1184
  isBeforeYesterday(date) {
1177
1185
  return this.adapter.daysFromToday(date) <= -2;
1178
1186
  }
1179
1187
  isYesterday(date) {
1180
- const interval = this.adapter.daysFromToday(date);
1181
- return interval > -2 && interval <= -1;
1188
+ return this.adapter.daysFromToday(date) === -1;
1182
1189
  }
1183
1190
  isToday(date) {
1184
1191
  return this.adapter.daysFromToday(date) === 0;
1185
1192
  }
1186
1193
  isTomorrow(date) {
1187
- const interval = this.adapter.daysFromToday(date);
1188
- return interval >= 1 && interval < 2;
1194
+ return this.adapter.daysFromToday(date) === 1;
1189
1195
  }
1190
1196
  isAfterTomorrow(date) {
1191
1197
  return this.adapter.daysFromToday(date) >= 2;