Skip to content

Commit

Permalink
fix: 完善回复中对方误把小数点写成冒号、导致无法确认这是个时间格式的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuiffy committed Mar 3, 2023
1 parent 2970c64 commit 9454847
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/Sentence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function Sentence({
}) {
const baseUrl = `https://www.bilibili.com/video/${bvId}`;

const matchResult = sentence.match(/\s*(\d+\.\d+)(.*)/);
const matchResult = sentence.match(/\s*(\d+[\.:]\d+)(.*)/);
if (matchResult) {
const seconds = matchResult[1];
const { formattedContent, timestamp } = extractTimestamp(matchResult);
Expand Down
2 changes: 1 addition & 1 deletion pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const Home: NextPage = () => {
const summaryArray = summary.split("- ");
const formattedSummary = summaryArray
.map((s) => {
const matchResult = s.match(/\s*(\d+\.\d+)(.*)/);
const matchResult = s.match(/\s*(\d+[\.:]\d+)(.*)/);
if (matchResult) {
const { formattedContent, timestamp } = extractTimestamp(matchResult);
return timestamp + formattedContent;
Expand Down
4 changes: 2 additions & 2 deletions utils/extractTimestamp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export function extractTimestamp(matchResult: RegExpMatchArray) {
console.log("========matchResult========", matchResult);
let timestamp: string | undefined;
const seconds = Number(matchResult[1]);
const seconds = Number(matchResult[1].replace(':', '.'));
const hours = Math.floor(seconds / 3600);
const remainingSeconds = Math.floor(seconds % 3600);
const minutes = Math.floor(remainingSeconds / 60);
Expand All @@ -26,5 +25,6 @@ export function extractTimestamp(matchResult: RegExpMatchArray) {
}catch(e){
console.log('handle text after time error', e);
}
console.log("========matchResult========", {matchResult, timestamp, formattedContent});
return { timestamp, formattedContent };
}

0 comments on commit 9454847

Please sign in to comment.