Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(quantic): fixed display of timestamps in youtube templates #4676

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div slot="excerpt">
{result.Excerpt}
</div>
<div slot="bottom-metadata" class="slds-text-align_left slds-m-top_xx-small" style="font-size: 10px">
<div slot="bottom-metadata" class="slds-text-align_left slds-m-top_xx-small slds-grid slds-grid_vertical-align-center" style="font-size: 10px">
<lightning-icon icon-name="utility:clock" size="xx-small"></lightning-icon>
<span class="slds-m-left_xxx-small">{videoTimeSpan}</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div slot="excerpt">
<c-quantic-result-highlighted-text-field engine-id={engineId} result={result} field="excerpt"></c-quantic-result-highlighted-text-field>
</div>
<div slot="bottom-metadata" class="slds-text-align_left slds-m-top_xx-small" style="font-size: 10px">
<div slot="bottom-metadata" class="slds-text-align_left slds-m-top_xx-small slds-grid slds-grid_vertical-align-center" style="font-size: 10px">
<lightning-icon icon-name="utility:clock" size="xx-small"></lightning-icon>
<span class="slds-m-left_xxx-small">{videoTimeSpan}</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class QuanticCategoryFacet extends LightningElement {
* ```
*
* @api
* @type {DependsOn} - An object defining the `parentFacetId` and `expectedValue` properties.
* @type {DependsOn}
*/
@api dependsOn;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class QuanticDateFacet extends LightningElement {
* ```
*
* @api
* @type {DependsOn} - An object defining the `parentFacetId` and `expectedValue` properties.
* @type {DependsOn}
*/
@api dependsOn;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default class QuanticFacet extends LightningElement {
* ```
*
* @api
* @type {DependsOn} - An object defining the `parentFacetId` and `expectedValue` properties.
* @type {DependsOn}
*/
@api dependsOn;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default class QuanticNumericFacet extends LightningElement {
* ```
*
* @api
* @type {DependsOn} - An object defining the `parentFacetId` and `expectedValue` properties.
* @type {DependsOn}
*/
@api dependsOn;
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class QuanticResult extends LightningElement {
return new TimeSpan(
this.result.raw.ytvideoduration,
false
).getCleanHHMMSS();
).getYoutubeFormatTimestamp();
}

onHasPreview = (evt) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default class QuanticTimeframeFacet extends LightningElement {
* ```
*
* @api
* @type {DependsOn} - An object defining the `parentFacetId` and `expectedValue` properties.
* @type {DependsOn}
*/
@api dependsOn;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
I18nUtils,
buildTemplateTextFromResult,
copyToClipboard,
TimeSpan,
} from 'c/quanticUtils';

describe('c/quanticUtils', () => {
Expand Down Expand Up @@ -200,4 +201,23 @@ describe('c/quanticUtils', () => {
);
});
});

describe('TimeSpan', () => {
describe('getYoutubeFormatTimestamp', () => {
it('should return the correct YouTube timestamp format for timestamps of less than a minute', () => {
const timeSpan = new TimeSpan(45000); // 45 seconds
expect(timeSpan.getYoutubeFormatTimestamp()).toBe('0:45');
});

it('should return the correct YouTube timestamp format for timestamps of more than an hour', () => {
const timeSpan = new TimeSpan(3661000); // 1 hour, 1 minute, and 1 second
expect(timeSpan.getYoutubeFormatTimestamp()).toBe('1:01:01');
});

it('should return the correct YouTube timestamp format for timestamps of less than an hour', () => {
const timeSpan = new TimeSpan(300000); // 5 minutes
expect(timeSpan.getYoutubeFormatTimestamp()).toBe('05:00');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,22 @@ export class TimeSpan {
return hhmmss;
}

getYoutubeFormatTimestamp() {
const hours = Math.floor(this.getHours());
const minutes = Math.floor(this.getMinutes()) % 60;
const seconds = Math.floor(this.getSeconds()) % 60;

const formattedSeconds = seconds < 10 ? '0' + seconds : seconds;

if (hours > 0) {
const formattedMinutes = minutes < 10 ? '0' + minutes : minutes;
return hours + ':' + formattedMinutes + ':' + formattedSeconds;
}
const formattedMinutes =
minutes === 0 ? '0' : minutes < 10 ? '0' + minutes : minutes;
return formattedMinutes + ':' + formattedSeconds;
}

getCleanHHMMSS() {
return this.getHHMMSS().replace(/^0+/, '');
}
Expand Down
Loading