Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
formatDate(date, dateFormat, timezone) {
timezone = timezone || 'UTC';
// Gloablize requires the locale to use a `-` rather than a `_`
const globalizeLocale = locale.replace('_', '-');
// Globalize can't handle our TZ dates, so we'll make a regular Date object that will look like it's from the tenant timezone when serialized in UTC
const kludgeDate = new TZ.timezone.Date(date.valueOf(), timezone);
kludgeDate.setMinutes(kludgeDate.getMinutes() + kludgeDate.getTimezoneOffset() * 2);
// Return a properly formatted date
const formatted = Globalize.format(kludgeDate, dateFormat, globalizeLocale);
return formatted.toString();
}
},
private formatDisplayValueFromLimit(value: RangeType) {
switch (this.valueFormat) {
case DynamicFacetRangeValueFormat.number:
const numberOfDecimals = NumberUtils.countDecimals(`${value}`);
return Globalize.format(value, `n${numberOfDecimals}`);
case DynamicFacetRangeValueFormat.currency:
return CurrencyUtils.currencyToString(parseFloat(`${value}`), {
symbol: this.facet.options.currencySymbol,
decimals: NumberUtils.countDecimals(`${value}`) ? 2 : 0
});
case DynamicFacetRangeValueFormat.date:
return DateUtils.dateToString(this.parseDateFromRangeType(value), {
alwaysIncludeTime: false,
includeTimeIfThisWeek: false,
includeTimeIfToday: false,
omitYearIfCurrentOne: false,
useTodayYesterdayAndTomorrow: false,
useWeekdayIfThisWeek: false
});
private translateValueCaptionFromFunctionName(facetValue: IIndexFieldValue) {
const { start, end } = this.extractStartAndEndValue(facetValue);
if (start == null || end == null) {
return null;
}
const helper = TemplateHelpers.getHelper(this.options.valueCaption);
if (helper != null) {
return `${helper.call(this, start)} - ${helper.call(this, end)}`;
} else {
const startConverted = start.match(/^[\+\-]?[0-9]+(\.[0-9]+)?$/) ? Number(start) : DateUtils.convertFromJsonDateIfNeeded(start);
const endConverted = end.match(/^[\+\-]?[0-9]+(\.[0-9]+)?$/) ? Number(end) : DateUtils.convertFromJsonDateIfNeeded(end);
return `${Globalize.format(startConverted, this.options.valueCaption)} - ${Globalize.format(
endConverted,
this.options.valueCaption
)}`;
}
}
instantiateToString(object?: IQueryResult, instantiateOptions?: IInstantiateTemplateOptions): string {
var preview =
"<div class="coveo-result-frame">" +
"<div class="coveo-result-row">" +
"<div style="width: 40px; padding-right:5px;vertical-align: middle" class="coveo-result-cell">" +
"<a data-small="true" class="CoveoIcon"></a>" +
'</div>' +
"<div style="font-size:13px;vertical-align: middle" class="coveo-result-cell">" +
"<a class="CoveoResultLink"></a>" +
'</div>' +
"<div style="width:80px; text-align:right; font-size:13px; padding-right: 5px;vertical-align: middle" class="coveo-result-cell">" +
Globalize.format(parseInt(object.raw[this.computedField.slice(1)]), this.format) +
'</div>' +
'</div>' +
'</div>';
return preview;
}
private formatQueryDuration(durationInMillis: number): string {
if (durationInMillis == undefined) {
return l('Unavailable');
} else {
var seconds = Math.max(durationInMillis / 1000, 0.01);
if (String['locale'] === 'en') {
return l('Seconds', Globalize.format(seconds, 'n2'), seconds, true);
} else {
return l('Seconds', Globalize.format(seconds, 'n2'), seconds);
}
}
}
}
private buildCollapsed() {
const numberOfSelected = filter(this.collapsed, (value: FacetValue) => value.selected).length;
const numberOfExcluded = filter(this.collapsed, (value: FacetValue) => value.excluded).length;
Assert.check(numberOfSelected + numberOfExcluded == this.collapsed.length);
const elem = $$('div', {
className: 'coveo-facet-breadcrumb-value'
});
const multiCount = $$('span', {
className: 'coveo-facet-breadcrumb-multi-count'
});
multiCount.text(l('NMore', Globalize.format(numberOfSelected + numberOfExcluded, 'n0')));
elem.append(multiCount.el);
const valueElements = map(this.collapsed, facetValue => {
return new this.breadcrumbValueElementKlass(this.facet, facetValue);
});
const toolTips = map(valueElements, valueElement => {
return valueElement.getBreadcrumbTooltip();
});
elem.el.setAttribute('title', toolTips.join('\n'));
elem.on('click', () => {
const elements: HTMLElement[] = [];
each(valueElements, valueElement => {
elements.push(valueElement.build().el);
});
private static getSummaryStrings(data: IQuerySuccessEventArgs): ISummaryStrings {
const queryPerformed = data.query;
const queryResults = data.results;
const first = Globalize.format(queryPerformed.firstResult + 1, 'n0');
const last = Globalize.format(queryPerformed.firstResult + queryResults.results.length, 'n0');
const totalCount = Globalize.format(queryResults.totalCountFiltered, 'n0');
const query = QuerySummaryUtils.sanitizeQuery(queryPerformed);
return { first, last, totalCount, query };
}
private formatQueryDuration(durationInMillis: number): string {
if (durationInMillis == undefined) {
return l('Unavailable');
} else {
var seconds = Math.max(durationInMillis / 1000, 0.01);
if (String['locale'] === 'en') {
return l('Seconds', Globalize.format(seconds, 'n2'), seconds, true);
} else {
return l('Seconds', Globalize.format(seconds, 'n2'), seconds);
}
}
}
}
private getFormattedCount(count: number) {
return Globalize.format(count, 'n0');
}