Drying out
This commit is contained in:
@@ -1,23 +1,11 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { toLocalDatetimeInputValue, toUTCFromLocalInput } from '../../utils/time';
|
||||
|
||||
interface TimeAdjusterProps {
|
||||
onTimeChange: (time: string) => void;
|
||||
defaultValue?: string;
|
||||
}
|
||||
|
||||
function toLocalDatetimeInputValue(date: Date): string {
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||||
}
|
||||
|
||||
function toUTCFromLocalInput(inputValue: string): string {
|
||||
const [datePart, timePart] = inputValue.split('T');
|
||||
const [year, month, day] = datePart.split('-').map(Number);
|
||||
const [hours, minutes] = timePart.split(':').map(Number);
|
||||
const localDate = new Date(year, month - 1, day, hours, minutes);
|
||||
return localDate.toISOString();
|
||||
}
|
||||
|
||||
const TimeAdjuster: React.FC<TimeAdjusterProps> = ({ onTimeChange, defaultValue }) => {
|
||||
const [value, setValue] = useState(() => {
|
||||
if (defaultValue) {
|
||||
|
||||
Reference in New Issue
Block a user