formatter

Playtech.API. formatter

Methods

# (static) date(srcDate, customFormatopt, localeopt) → {string}

Gets date in custom format.
Parameters:
Name Type Attributes Default Description
srcDate Date | string
customFormat string <optional>
date
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Examples
// '12-04-2022'
Playtech.API.formatter.date(new Date(2022, 03, 12), '%d-%m-%Y');
// 'Wed-Jun-6/22/2022, 9:32:07 AM-20-22-06/22/22- 6-6th'
Playtech.API.formatter.date(new Date('Wed Jun 22 2022 09:32:07 GMT+0300 (Eastern European Summer Time)'), '%a-%b-%c-%C-%d-%D-%e-%E');
// '09-09-172-06-32-AM-09:32:07 AM-09:32'
Playtech.API.formatter.date(new Date('Wed Jun 22 2022 09:32:07 GMT+0300 (Eastern European Summer Time)'), '%H-%I-%j-%m-%M-%p-%r-%R');
// '07-000-09:32:07-6/22/2022-9:32:07 AM-22-2022--0180'
Playtech.API.formatter.date(new Date('Wed Jun 22 2022 09:32:07 GMT+0300 (Eastern European Summer Time)'), '%S-%SSS-%T-%x-%X-%y-%Y-%Z');

# (static) delocalizeNumber(str, optionsopt) → {*|number|string}

Convert string, that represents localized number, into number if possible.
Parameters:
Name Type Attributes Description
str string Source string.
options Object <optional>
Source format params.
Properties
Name Type Attributes Default Description
thSeparator string <optional>
, Thousand separator.
decSeparator string <optional>
. Decimal separator.
Returns:
Type
* | number | string
Examples
// 1234567890
Playtech.API.formatter.delocalizeNumber('1,234,567,890*00', {thSeparator: ',', decSeparator: '*'});
// 'foobar'
Playtech.API.formatter.delocalizeNumber('foobar', {thSeparator: ',', decSeparator: '*'});

# (static) formatCurrency(amount, optionsopt, localeopt) → {string}

Formats amount in currency according to options.
Parameters:
Name Type Attributes Description
amount number | string Amount to format.
options Object <optional>
Formatter params.
Properties
Name Type Attributes Default Description
locale string <optional>
If not passed, user's locale is used.
currencyCode string <optional>
Currency, if not passed, user's currency is used.
symbolAtTheLeft string <optional>
true 'true' to draw currency symbol to the left of amount.
precision number <optional>
2 Decimal precision.
thSeparator string <optional>
, Thousand separator.
decSeparator string <optional>
. Decimal separator.
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Examples
// 'GB 45.00'
Playtech.API.formatter.formatCurrency(45, {currencyCode: "GB"});
// '£ 45.00'
Playtech.API.formatter.formatCurrency(45, {}, 'de_DE');
// '4:567*000 £'
Playtech.API.formatter.formatCurrency('4567', {symbolAtTheLeft: false, precision: 3, thSeparator: ':', decSeparator: '*'});

# (static) formatNumber(number, optionsopt, localeopt) → {string}

Formats number according to options.
Parameters:
Name Type Attributes Description
number number | string Number to format.
options Object <optional>
Format params.
Properties
Name Type Attributes Default Description
precision number <optional>
null Decimal precision.
thSeparator string <optional>
, {string} Thousand separator.
decSeparator string <optional>
. Decimal separator.
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Examples
// '1,234,567,890*00'
Playtech.API.formatter.formatNumber('1234567890', {precision: 2 , thSeparator: ',', decSeparator: '*'});
// '1,234,567,890'
Playtech.API.formatter.formatNumber('1234567890');

# (static) formatTimeFromSeconds(seconds) → {string}

Converts seconds to HH:MM:SS or MM:SS.
Parameters:
Name Type Description
seconds string | number
Returns:
Type
string
Example
// '01:05'
Playtech.API.formatter.formatTimeFromSeconds(65);

# (static) getCurrencySymbol(optionsopt) → {string}

Gets currency symbol to display.
Parameters:
Name Type Attributes Description
options string | Object <optional>
Currency code or currency options, if not passed, user's currency is used.
Properties
Name Type Attributes Description
currencyCode string <optional>
Currency code
Returns:
Type
string
Example
// '$'
Playtech.API.formatter.getCurrencySymbol({ currencyCode: "USD" });

# (static) getDate(srcDate, localeopt) → {string}

Gets date in 'date' format e.g. YYYY-MM-DD Depends on Date/Time format setting in CMS.
Parameters:
Name Type Attributes Description
srcDate * | Date | string
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Examples
// '22/06/2022'
Playtech.API.formatter.getDate();
// '19/08/2014'
Playtech.API.formatter.getDate('2014-08-19T18:59:21+02:00');

# (static) getDateForCsv(srcDate, localeopt) → {string}

Formats date for export to CSV in 'YYYY-MM-DD' format.
Parameters:
Name Type Attributes Description
srcDate * | Date | string
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Example
// '2022-05-05'
Playtech.API.formatter.getDateForCsv('Wed May 05 2022 03:40:11 GMT+0300');

# (static) getDateForIms(srcDate) → {string}

Get date in format 'YYYY-MM-DD HH:MM:SS.sss' in GMT to be sent to IMS (through OGW).
Parameters:
Name Type Description
srcDate Date
Returns:
Type
string
Example
// '2021-04-14 00:40:11.000'
Playtech.API.formatter.getDateForIms(new Date('Wed Apr 14 2021 03:40:11 GMT+0300'));

# (static) getDateTimeForCsv(srcDate, localeopt) → {string}

Formats date and time for export to CSV in 'YYYY-MM-DD HH:MM' format.
Parameters:
Name Type Attributes Description
srcDate * | Date | string
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Example
// '2022-05-05 03:40'
Playtech.API.formatter.getDateTimeForCsv('Wed May 05 2022 03:40:11 GMT+0300');

# (static) getDateTimeLong(srcDate, localeopt) → {string}

Gets date in 'dateTimeLong' format e.g YYYY-MM-DD HH:MM:SS Depends on Date/Time format setting in CMS.
Parameters:
Name Type Attributes Description
srcDate * | Date | string
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Example
// '22/06/2022 09:55:11 AM'
Playtech.API.formatter.getDateTimeLong(new Date('Wed Jun 22 2022 09:55:11 GMT+0300'));

# (static) getDateTimeLongMs(srcDate, localeopt) → {string}

Gets date in 'dateTimeLongMs' format e.g YYYY-MM-DD HH:MM:SS.sss Depends on Date/Time format setting in CMS.
Parameters:
Name Type Attributes Description
srcDate * | Date | string
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Example
// '2022-02-24 02:40:11.000'
Playtech.API.formatter.getDateTimeLongMs(new Date('Wed Feb 24 2022 03:40:11 GMT+0300'));

# (static) getDateTimeShort(srcDate, localeopt) → {string}

Gets date in 'dateTimeShort' format e.g YYYY-MM-DD HH:MM Depends on Date/Time format setting in CMS.
Parameters:
Name Type Attributes Description
srcDate * | Date | string
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Example
// '2022-06-22 09:55'
Playtech.API.formatter.getDateTimeShort(new Date('Wed Jun 22 2022 09:55:11 GMT+0300'));

# (static) getDurationTimeLong(duration) → {string}

Get duration in 'HH:MM:SS' format without timezone offset.
Parameters:
Name Type Description
duration Date | string | number
Returns:
Type
string
Example
// '11:39:18'
Playtech.API.formatter.getDurationTimeLong(new Date('Wed Jun 12 2022 14:39:18 GMT+0300'));

# (static) getDurationTimeShort(duration) → {string}

Get duration in 'HH:MM' format without timezone offset.
Parameters:
Name Type Description
duration Date | string | number
Returns:
Type
string
Example
// '11:39'
Playtech.API.formatter.getDurationTimeShort(new Date('Wed Jun 12 2022 14:39:18 GMT+0300'));

# (static) getIsCurrencySymbolAtTheLeft(optionsopt) → {boolean}

Parameters:
Name Type Attributes Description
options Object <optional>
SymbolAtTheLeft options.
Properties
Name Type Attributes Description
symbolAtTheLeft string <optional>
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
boolean
Examples
// true
Playtech.API.formatter.getIsCurrencySymbolAtTheLeft({currencyCode: "USD"});
// false
Playtech.API.formatter.getIsCurrencySymbolAtTheLeft({symbolAtTheLeft: false});

# (static) getLocaleDateShort(srcDate, localeopt) → {string}

Gets date in '12 Apr 2018' format.
Parameters:
Name Type Attributes Description
srcDate * | Date | string
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Example
// '5 May 2022'
Playtech.API.formatter.getLocaleDateShort('Wed May 05 2022 03:40:11 GMT+0300');

# (static) getTimeLong(srcDate, localeopt) → {string}

Gets date in 'timeLong' format e.g HH:MM:SS Depends on Date/Time format setting in CMS.
Parameters:
Name Type Attributes Description
srcDate * | Date | string
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Examples
// '19/08/2014'
Playtech.API.formatter.getTimeLong('2014-08-19T18:59:21+02:00');
// '12:06:30 PM'
Playtech.API.formatter.getTimeLong("2014-08-22T12:06:30.0200");

# (static) getTimeShort(srcDate, localeopt) → {string}

Gets date in 'timeShort' format e.g HH:MM Depends on Date/Time format setting in CMS.
Parameters:
Name Type Attributes Description
srcDate * | Date | string
locale string <optional>
If not passed, user's locale is used.
Returns:
Type
string
Examples
// '09:55 AM'
Playtech.API.formatter.getTimeShort(new Date('Wed Jun 22 2022 09:55:11 GMT+0300'));
// '14:55'
Playtech.API.formatter.getTimeShort(new Date('Wed Jun 22 2022 14:55:11 GMT+0300'));

# (static) parseImsBankIdDate(scrDate) → {Date}

Parse date string received from getUrlRequest. IMS sends us date in non-standard format ('YYYY-MM-DD+HH%3AMM%3ASS.sss') without specifying time zone, but according to IMS documentation, this time always comes in GMT.
Parameters:
Name Type Description
scrDate string
Returns:
Type
Date
Example
// Mon May 09 2022 17:45:45 GMT+0300 (Eastern European Summer Time)
Playtech.API.formatter.parseImsBankIdDate('2022-05-09+14%3A45%3A45.456');

# (static) parseImsDate(srcDate) → {Date}

Parse date string received from IMS. IMS sends us date in non-standard format ('YYYY-MM-DD HH:MM:SS.sss') without specifying time zone, but according to IMS documentation, this time always comes in GMT.
Parameters:
Name Type Description
srcDate string
Returns:
Type
Date
Example
// Fri May 06 2022 17:45:21 GMT+0300 (Eastern European Summer Time)
Playtech.API.formatter.parseImsDate('2022-05-06 14:45:21.567');