Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
semkedaniil committed Jun 14, 2024
1 parent 69d498d commit 20019b7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion db-viewer-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"react-router-dom": ">=6 <7"
},
"dependencies": {
"@skbkontur/edi-ui": "^0.2.2",
"@skbkontur/edi-ui": "^0.2.3",
"@skbkontur/react-stack-layout": "^1.0.3",
"@skbkontur/react-ui-validations": "^1.8.3",
"date-fns": "^2.29.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RussianDateFormat, parseDate, Time, TimeZone, TimeUtils, StringUtils, formatDate } from "@skbkontur/edi-ui";
import { RussianDateFormat, Time, TimeZone, TimeUtils, StringUtils, DateUtils } from "@skbkontur/edi-ui";
import { DatePicker as DefaultDatePicker } from "@skbkontur/react-ui";
import React from "react";

Expand Down Expand Up @@ -83,15 +83,15 @@ export class DatePicker extends React.Component<DatePickerProps, DatePickerState

private readonly convertStringToDate = (newStringifiedDate: RussianDateFormat): Date => {
const { timeZone } = this.props;
const date = parseDate(newStringifiedDate);
const ISODate = formatDate(date, "yyyy-MM-dd");
const date = DateUtils.parseDate(newStringifiedDate);
const ISODate = DateUtils.formatDate(date, "yyyy-MM-dd");
const time = this.props.defaultTime || defaultTime;
const timeZoneOffset = TimeUtils.getTimeZoneOffsetOrDefault(timeZone);
return new Date(`${ISODate}T${time}${TimeUtils.timeZoneOffsetToString(timeZoneOffset)}`);
};

private readonly convertDateToStringWithTimezone = (date: Nullable<Date | string>, timeZone?: number) => {
const timeZoneOffset = TimeUtils.getTimeZoneOffsetOrDefault(timeZone);
return date ? formatDate(date, "dd.MM.yyyy", timeZoneOffset) : "";
return date ? DateUtils.formatDate(date, "dd.MM.yyyy", timeZoneOffset) : "";
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Time, TimeZone, TimeUtils, formatDate } from "@skbkontur/edi-ui";
import { Time, TimeZone, TimeUtils, DateUtils } from "@skbkontur/edi-ui";
import React from "react";

import { DatePicker } from "./DatePicker";
Expand Down Expand Up @@ -31,7 +31,7 @@ export function DateTimePicker({
}

const timeZoneOffset = TimeUtils.getTimeZoneOffsetOrDefault(timeZone);
const date = formatDate(value, "yyyy-MM-dd", timeZoneOffset);
const date = DateUtils.formatDate(value, "yyyy-MM-dd", timeZoneOffset);
const newDateTime = new Date(`${date}T${newTime}${TimeUtils.timeZoneOffsetToString(timeZoneOffset)}`);
onChange(newDateTime);
};
Expand All @@ -42,7 +42,7 @@ export function DateTimePicker({
}

const timeZoneOffset = TimeUtils.getTimeZoneOffsetOrDefault(timeZone);
const time = formatDate(date, "HH:mm", timeZoneOffset);
const time = DateUtils.formatDate(date, "HH:mm", timeZoneOffset);
setTime(time);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatDate, fromLocalToUtc, Time } from "@skbkontur/edi-ui";
import { DateUtils, Time } from "@skbkontur/edi-ui";
import { Select } from "@skbkontur/react-ui";
import React, { useState, useEffect } from "react";

Expand Down Expand Up @@ -38,7 +38,7 @@ export const DateTimePickerWithTimeZone = ({
onChange(null);
return;
}
const date = formatDate(newDate, "yyyy-MM-dd", 0);
const date = DateUtils.formatDate(newDate, "yyyy-MM-dd", 0);
const newDateTime = `${date}T${newTime ?? defaultTime}${newOffset ?? ""}`;
onChange(newDateTime);
};
Expand All @@ -50,8 +50,8 @@ export const DateTimePickerWithTimeZone = ({
const timeOffset = getTimeZoneString(dateStr);
setOffset(timeOffset);
const dateTimeWithoutTimezone = timeOffset ? dateStr.slice(0, -timeOffset.length) : dateStr;
setDate(fromLocalToUtc(new Date(dateTimeWithoutTimezone)));
setTime(formatDate(dateTimeWithoutTimezone, "HH:mm:ss.SSS"));
setDate(DateUtils.fromLocalToUtc(new Date(dateTimeWithoutTimezone)));
setTime(DateUtils.formatDate(dateTimeWithoutTimezone, "HH:mm:ss.SSS"));
};

const getTimeZoneString = (date: string): Nullable<string> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Time } from "@skbkontur/edi-ui";
import { Time, TimeUtils } from "@skbkontur/edi-ui";
import { Input } from "@skbkontur/react-ui";
import React, { useEffect, useState } from "react";

Expand Down Expand Up @@ -39,10 +39,9 @@ export const TimePicker = ({
setValue(value);
};

const isCorrectTime = (time: string) => Boolean(time.match(/^([01]?[0-9]|2[0-3]):[0-5][0-9]/));
const handleBlur = () => {
const trimmed = value.endsWith(".") || value.endsWith(":") ? value.slice(0, -1) : value;
if (isCorrectTime(trimmed)) {
if (TimeUtils.isCorrectTime(trimmed)) {
onChange(trimmed);
if (defaultTime === trimmed) {
setValue(emptyValue);
Expand All @@ -54,7 +53,7 @@ export const TimePicker = ({
};

const handleFocus = () => {
if (!isCorrectTime(value)) {
if (!TimeUtils.isCorrectTime(value)) {
setValue(defaultTime);
}
};
Expand Down
10 changes: 5 additions & 5 deletions db-viewer-ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2299,7 +2299,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@skbkontur/db-viewer-ui@workspace:."
dependencies:
"@skbkontur/edi-ui": "npm:^0.2.2"
"@skbkontur/edi-ui": "npm:^0.2.3"
"@skbkontur/icons": "npm:^1.7.3"
"@skbkontur/react-selenium-testing": "npm:^0.2.1"
"@skbkontur/react-stack-layout": "npm:^1.0.3"
Expand Down Expand Up @@ -2346,9 +2346,9 @@ __metadata:
languageName: unknown
linkType: soft

"@skbkontur/edi-ui@npm:^0.2.2":
version: 0.2.2
resolution: "@skbkontur/edi-ui@npm:0.2.2"
"@skbkontur/edi-ui@npm:^0.2.3":
version: 0.2.3
resolution: "@skbkontur/edi-ui@npm:0.2.3"
dependencies:
"@skbkontur/colors": "npm:0.4.4"
"@skbkontur/icons": "npm:1.10.0"
Expand All @@ -2362,7 +2362,7 @@ __metadata:
"@skbkontur/react-ui": ">=4"
react: ">=16 <=18"
react-dom: ">=16 <=18"
checksum: fdeb778443a969cf8f66ea600d46d664bc2d2543dd9763361579067087ff3d41ff15e15cd2d0da24cf063313ca84fe9d058bbb523601bcb92cde81a1d99a155a
checksum: 98b20235ecd51367140c419929aafffaaac526f1d4dcc47890a0849243d1398dc00215331eca8d84d7d1f86117f7580d964650c6624c1731f6424ed7669ab780
languageName: node
linkType: hard

Expand Down

0 comments on commit 20019b7

Please sign in to comment.