Fix time input for casting (#94)
This commit is contained in:
1 parent
cc78fb0ec1
commit
c705ce86d3
2 files changed
+41
-16
No files matched your search
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Video duration formatting in cast dialog
|
||||||
|
|
||||||
## [0.10.1] - 2023-06-28
|
## [0.10.1] - 2023-06-28
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (document.activeElement !== textInputElemet) {
|
if (document.activeElement !== textInputElemet) {
|
||||||
timestampText = getTimeStampText(timestamp);
|
timestampText = getFormattedTime(timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,27 +19,38 @@
|
|||||||
if (timestampText === "") {
|
if (timestampText === "") {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const match = /^(\d{1,3}):(\d{1,2})$/.exec(timestampText);
|
|
||||||
|
const match = /^((\d+):)?(\d{1,2}):(\d{1,2})$/.exec(timestampText);
|
||||||
if (match) {
|
if (match) {
|
||||||
const minutes = parseInt(match[1]);
|
const hours = match[2] ? parseInt(match[2]) : 0;
|
||||||
const seconds = parseInt(match[2]);
|
const minutes = parseInt(match[3]);
|
||||||
if (seconds < 60) {
|
const seconds = parseInt(match[4]);
|
||||||
return minutes * 60 + seconds;
|
|
||||||
|
if (minutes < 60 && seconds < 60) {
|
||||||
|
return hours * 3600 + minutes * 60 + seconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTimeStampText(timestamp) {
|
function getFormattedTime(length) {
|
||||||
if (timestamp === undefined) {
|
if (length === undefined) {
|
||||||
return "";
|
return undefined;
|
||||||
}
|
}
|
||||||
const minutes = Math.floor(timestamp / 60);
|
const hours = Math.floor(length / 3600);
|
||||||
const remainingSeconds = timestamp % 60;
|
const minutes = Math.floor((length / 60) % 60);
|
||||||
|
const seconds = length % 60;
|
||||||
|
|
||||||
const formattedMinutes = String(minutes);
|
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
|
||||||
const formattedSeconds = String(remainingSeconds).padStart(2, "0");
|
const minutesString =
|
||||||
|
minutes < 10 && hours > 0 ? `0${minutes}` : minutes.toString();
|
||||||
|
|
||||||
return `${formattedMinutes}:${formattedSeconds}`;
|
let formattedTime = minutesString + ":" + secondsString;
|
||||||
|
|
||||||
|
if (hours > 0) {
|
||||||
|
formattedTime = hours.toString() + ":" + formattedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedTime;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -52,11 +63,19 @@
|
|||||||
<input
|
<input
|
||||||
bind:this={textInputElemet}
|
bind:this={textInputElemet}
|
||||||
disabled={!checked}
|
disabled={!checked}
|
||||||
class="input w-24"
|
class="input w-28"
|
||||||
placeholder="0:00"
|
placeholder="0:00"
|
||||||
bind:value={timestampText}
|
bind:value={timestampText}
|
||||||
on:input={(e) => {
|
on:input={(e) => {
|
||||||
timestamp = getTimeStamp(e.currentTarget.value);
|
let newTimestamp = getTimeStamp(e.currentTarget.value);
|
||||||
|
if (newTimestamp !== undefined && lengthSeconds) {
|
||||||
|
newTimestamp = Math.min(newTimestamp, lengthSeconds);
|
||||||
|
}
|
||||||
|
timestamp = newTimestamp;
|
||||||
|
}}
|
||||||
|
on:change={(e) => {
|
||||||
|
timestampText = getFormattedTime(timestamp) ?? "0:00";
|
||||||
|
timestamp = getTimeStamp(timestampText);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{#if checked}
|
{#if checked}
|
||||||
|
|||||||
Reference in new issue
Block a user