@nemigo/helpers 0.4.1 → 0.4.2

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.
@@ -34,6 +34,7 @@ export declare const formatDateTime: (datetime?: Date | Timestamp | string, form
34
34
  *
35
35
  * @param date - Строка даты в формате "DD.MM.YYYY"
36
36
  * @param [time="00:00"] - Строка времени в формате "HH:MM"
37
+ * @param [timezone] - Часовой пояс относительно GMT
37
38
  *
38
39
  * @returns TimeStamp соответствующий указанной дате и времени или 0 при неверном формате
39
40
  *
@@ -41,4 +42,4 @@ export declare const formatDateTime: (datetime?: Date | Timestamp | string, form
41
42
  * const timestamp = toTimeStamp("11.02.2012", "13:45");
42
43
  * console.log(timestamp); // Выведет {@link Timestamp} для "11.02.2012 13:45"
43
44
  */
44
- export declare const toTimeStamp: (date: string, time?: string) => Timestamp | 0;
45
+ export declare const toTimeStamp: (date: string, time?: string, timezone?: number) => Timestamp | 0;
package/dist/datetime.js CHANGED
@@ -92,6 +92,7 @@ export const formatDateTime = (datetime = Date.now(), format = "DD.DM.DY TH:TM")
92
92
  *
93
93
  * @param date - Строка даты в формате "DD.MM.YYYY"
94
94
  * @param [time="00:00"] - Строка времени в формате "HH:MM"
95
+ * @param [timezone] - Часовой пояс относительно GMT
95
96
  *
96
97
  * @returns TimeStamp соответствующий указанной дате и времени или 0 при неверном формате
97
98
  *
@@ -99,12 +100,17 @@ export const formatDateTime = (datetime = Date.now(), format = "DD.DM.DY TH:TM")
99
100
  * const timestamp = toTimeStamp("11.02.2012", "13:45");
100
101
  * console.log(timestamp); // Выведет {@link Timestamp} для "11.02.2012 13:45"
101
102
  */
102
- export const toTimeStamp = (date, time = "00:00") => {
103
+ export const toTimeStamp = (date, time = "00:00", timezone) => {
103
104
  const [day, month, year] = date.split(".").map(Number);
104
105
  const [hours, minutes] = time.split(":").map(Number);
105
106
  // Проверка на корректность ввода (если хотя бы одно значение не число)
106
107
  // prettier-ignore
107
108
  if ([day, month, year, hours, minutes].some(isNaN))
108
109
  return 0;
109
- return new Date(year, month - 1, day, hours, minutes).valueOf();
110
+ if (timezone !== undefined) {
111
+ return Date.UTC(year, month - 1, day, hours, minutes) - timezone * 60 * 60 * 1000;
112
+ }
113
+ else {
114
+ return new Date(year, month - 1, day, hours, minutes).getTime();
115
+ }
110
116
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/helpers",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",