Skip to content

Commit

Permalink
feat: add to return entire section if no section is watched
Browse files Browse the repository at this point in the history
  • Loading branch information
alstjs1207 committed Jun 10, 2024
1 parent 859e3ea commit 3227ccb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/time-range/time-range.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ describe('TimeRange Util', () => {
});
});

describe('revert time section', () => {
it('unwatched time range', async () => {
describe('no time section', () => {
it('should be return unwatched time range', async () => {
const timeRange = new TimeRange();
timeRange.add({ end: 6.74336, start: 0, interval: 6.74336 });
timeRange.add({ end: 67.15486, start: 17, interval: 50.15486 });
Expand All @@ -282,6 +282,11 @@ describe('TimeRange Util', () => {
{ start: 419.22133, end: 500 },
]);
});
it('should be return entire section, if no section watched', async () => {
const timeRange = new TimeRange();
const result = timeRange.getUnwatchedTimeRange(500);
expect(result).toEqual([{ start: 0, end: 500 }]);
});
});
});
});
10 changes: 10 additions & 0 deletions src/time-range/time-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ export class TimeRange {
// 정렬된 시청 구간을 기준으로 미시청 구간을 계산
const timeRange = this.section.sort((a, b) => a.start - b.start);

// 시청 구간이 없는 경우 클립 전체를 미시청 구간으로 간주
if (timeRange.length === 0) {
return [
{
start: 0,
end: endTime,
},
];
}

// 클립의 시작부터 첫 시청 구간의 시작까지의 미시청 구간 추가
if (timeRange[0].start > 0) {
unwatchedTimeRange.push({
Expand Down

0 comments on commit 3227ccb

Please sign in to comment.