@commercetools-uikit/calendar-time-utils 18.2.0 → 18.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.
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
6
+ var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
6
7
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
7
8
  var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
8
9
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
@@ -16,6 +17,7 @@ var utils = require('@commercetools-uikit/utils');
16
17
 
17
18
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
18
19
 
20
+ var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
19
21
  var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
20
22
  var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
21
23
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
@@ -107,6 +109,27 @@ const changeTime = (dateString, timeZone, parsedTime) => {
107
109
  return date.toISOString();
108
110
  };
109
111
  const getPreviousDay = day => moment__default["default"](day).subtract(1, 'day').format('YYYY-MM-DD');
112
+ const formatDefaultTime = (time, locale) => {
113
+ const today = moment__default["default"]();
114
+ if (moment__default["default"](time, 'HH:mm', true).isValid()) {
115
+ const _time$split = time.split(':'),
116
+ _time$split2 = _slicedToArray(_time$split, 2),
117
+ hour = _time$split2[0],
118
+ minute = _time$split2[1];
119
+ today.set({
120
+ hour: _parseInt__default["default"](hour, 10),
121
+ minute: _parseInt__default["default"](minute, 10)
122
+ });
123
+ return moment__default["default"](today).locale(locale).format('LT'); // 5:13 PM
124
+ } else {
125
+ process.env.NODE_ENV !== "production" ? utils.warning(false, "DataTimeInput: the specified defaultDaySelectionTime '".concat(time, "' is not supported. The format should be hh:mm, e.g. 11:10. Using 00:00 as default time.")) : void 0;
126
+ today.set({
127
+ hour: 0,
128
+ minute: 0
129
+ });
130
+ return moment__default["default"](today).locale(locale).format('LT'); // 12:00 AM
131
+ }
132
+ };
110
133
  const formatTime = (day, locale, timeZone) => {
111
134
  const date = moment__default["default"].tz(day, timeZone).locale(locale);
112
135
  if (date.milliseconds()) return date.format('HH:mm:ss.SSS');
@@ -230,7 +253,7 @@ const getLocalizedDateTimeFormatPattern = function (locale) {
230
253
  };
231
254
 
232
255
  // NOTE: This string will be replaced on build time with the package version.
233
- var version = "18.2.0";
256
+ var version = "18.4.0";
234
257
 
235
258
  exports.changeDateInMonth = changeDateInMonth;
236
259
  exports.changeMonth = changeMonth;
@@ -239,6 +262,7 @@ exports.createCalendarItems = createCalendarItems;
239
262
  exports.createItemDateTimeToString = createItemDateTimeToString;
240
263
  exports.createSuggestedItems = createSuggestedItems;
241
264
  exports.formatDate = formatDate;
265
+ exports.formatDefaultTime = formatDefaultTime;
242
266
  exports.formatTime = formatTime;
243
267
  exports.getCalendarDayLabel = getCalendarDayLabel;
244
268
  exports.getDateInMonth = getDateInMonth;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
6
+ var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
6
7
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
7
8
  var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
8
9
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
@@ -16,6 +17,7 @@ var utils = require('@commercetools-uikit/utils');
16
17
 
17
18
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
18
19
 
20
+ var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
19
21
  var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
20
22
  var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
21
23
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
@@ -107,6 +109,26 @@ const changeTime = (dateString, timeZone, parsedTime) => {
107
109
  return date.toISOString();
108
110
  };
109
111
  const getPreviousDay = day => moment__default["default"](day).subtract(1, 'day').format('YYYY-MM-DD');
112
+ const formatDefaultTime = (time, locale) => {
113
+ const today = moment__default["default"]();
114
+ if (moment__default["default"](time, 'HH:mm', true).isValid()) {
115
+ const _time$split = time.split(':'),
116
+ _time$split2 = _slicedToArray(_time$split, 2),
117
+ hour = _time$split2[0],
118
+ minute = _time$split2[1];
119
+ today.set({
120
+ hour: _parseInt__default["default"](hour, 10),
121
+ minute: _parseInt__default["default"](minute, 10)
122
+ });
123
+ return moment__default["default"](today).locale(locale).format('LT'); // 5:13 PM
124
+ } else {
125
+ today.set({
126
+ hour: 0,
127
+ minute: 0
128
+ });
129
+ return moment__default["default"](today).locale(locale).format('LT'); // 12:00 AM
130
+ }
131
+ };
110
132
  const formatTime = (day, locale, timeZone) => {
111
133
  const date = moment__default["default"].tz(day, timeZone).locale(locale);
112
134
  if (date.milliseconds()) return date.format('HH:mm:ss.SSS');
@@ -230,7 +252,7 @@ const getLocalizedDateTimeFormatPattern = function (locale) {
230
252
  };
231
253
 
232
254
  // NOTE: This string will be replaced on build time with the package version.
233
- var version = "18.2.0";
255
+ var version = "18.4.0";
234
256
 
235
257
  exports.changeDateInMonth = changeDateInMonth;
236
258
  exports.changeMonth = changeMonth;
@@ -239,6 +261,7 @@ exports.createCalendarItems = createCalendarItems;
239
261
  exports.createItemDateTimeToString = createItemDateTimeToString;
240
262
  exports.createSuggestedItems = createSuggestedItems;
241
263
  exports.formatDate = formatDate;
264
+ exports.formatDefaultTime = formatDefaultTime;
242
265
  exports.formatTime = formatTime;
243
266
  exports.getCalendarDayLabel = getCalendarDayLabel;
244
267
  exports.getDateInMonth = getDateInMonth;
@@ -1,4 +1,5 @@
1
1
  import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
2
+ import _parseInt from '@babel/runtime-corejs3/core-js-stable/parse-int';
2
3
  import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
3
4
  import _sliceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/slice';
4
5
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
@@ -8,7 +9,7 @@ import _Map from '@babel/runtime-corejs3/core-js-stable/map';
8
9
  import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
9
10
  import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
10
11
  import moment from 'moment-timezone';
11
- import { parseTime } from '@commercetools-uikit/utils';
12
+ import { warning, parseTime } from '@commercetools-uikit/utils';
12
13
 
13
14
  // Reference: https://momentjs.com/docs/#/displaying/format/
14
15
  const formatToken = {
@@ -91,6 +92,27 @@ const changeTime = (dateString, timeZone, parsedTime) => {
91
92
  return date.toISOString();
92
93
  };
93
94
  const getPreviousDay = day => moment(day).subtract(1, 'day').format('YYYY-MM-DD');
95
+ const formatDefaultTime = (time, locale) => {
96
+ const today = moment();
97
+ if (moment(time, 'HH:mm', true).isValid()) {
98
+ const _time$split = time.split(':'),
99
+ _time$split2 = _slicedToArray(_time$split, 2),
100
+ hour = _time$split2[0],
101
+ minute = _time$split2[1];
102
+ today.set({
103
+ hour: _parseInt(hour, 10),
104
+ minute: _parseInt(minute, 10)
105
+ });
106
+ return moment(today).locale(locale).format('LT'); // 5:13 PM
107
+ } else {
108
+ process.env.NODE_ENV !== "production" ? warning(false, "DataTimeInput: the specified defaultDaySelectionTime '".concat(time, "' is not supported. The format should be hh:mm, e.g. 11:10. Using 00:00 as default time.")) : void 0;
109
+ today.set({
110
+ hour: 0,
111
+ minute: 0
112
+ });
113
+ return moment(today).locale(locale).format('LT'); // 12:00 AM
114
+ }
115
+ };
94
116
  const formatTime = (day, locale, timeZone) => {
95
117
  const date = moment.tz(day, timeZone).locale(locale);
96
118
  if (date.milliseconds()) return date.format('HH:mm:ss.SSS');
@@ -214,6 +236,6 @@ const getLocalizedDateTimeFormatPattern = function (locale) {
214
236
  };
215
237
 
216
238
  // NOTE: This string will be replaced on build time with the package version.
217
- var version = "18.2.0";
239
+ var version = "18.4.0";
218
240
 
219
- export { changeDateInMonth, changeMonth, changeTime, createCalendarItems, createItemDateTimeToString, createSuggestedItems, formatDate, formatTime, getCalendarDayLabel, getDateInMonth, getDaysInMonth, getLocalizedDateTimeFormatPattern, getMonthCalendarLabel, getPaddingDayCount, getPreviousDay, getStartOf, getToday, getWeekdayNames, getYearCalendarLabel, isSameDay, parseInputText, version };
241
+ export { changeDateInMonth, changeMonth, changeTime, createCalendarItems, createItemDateTimeToString, createSuggestedItems, formatDate, formatDefaultTime, formatTime, getCalendarDayLabel, getDateInMonth, getDaysInMonth, getLocalizedDateTimeFormatPattern, getMonthCalendarLabel, getPaddingDayCount, getPreviousDay, getStartOf, getToday, getWeekdayNames, getYearCalendarLabel, isSameDay, parseInputText, version };
@@ -9,6 +9,7 @@ export declare const getDaysInMonth: (day: MomentInput, timeZone: string) => num
9
9
  export declare const changeDateInMonth: (day: MomentInput, timeZone: string, dayOfMonth: number) => string;
10
10
  export declare const changeTime: (dateString: string, timeZone: string, parsedTime: ParsedTime) => string;
11
11
  export declare const getPreviousDay: (day: MomentInput) => string;
12
+ export declare const formatDefaultTime: (time: string, locale: LocaleSpecifier) => string;
12
13
  export declare const formatTime: (day: MomentInput, locale: LocaleSpecifier, timeZone: string) => string;
13
14
  export declare const formatDate: (day: MomentInput, locale: string, timeZone: string) => string;
14
15
  export declare const getDateInMonth: (day: MomentInput, timeZone: string) => number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/calendar-time-utils",
3
3
  "description": "Utilities to work with time values for a calendar.",
4
- "version": "18.2.0",
4
+ "version": "18.4.0",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@babel/runtime": "^7.20.13",
23
23
  "@babel/runtime-corejs3": "^7.20.13",
24
- "@commercetools-uikit/utils": "18.2.0"
24
+ "@commercetools-uikit/utils": "18.4.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "moment-timezone": "0.5.44"