File

projects/wms-framework/src/lib/baseframework/globalization.ts

Description

Numeric formats information

Index

Properties
Methods
Accessors

Constructor

constructor()

Creates an instance of NumberFormatInfo.

Properties

Private currencyDecimalDigits
Type : number
Default value : 2
Private currencyDecimalSeparator
Type : string
Default value : '.'
Private currencyGroupSeparator
Type : string
Default value : ','
Private currencyGroupSizes
Type : number[]
Default value : [3]
Private currencyNegativePattern
Type : number
Default value : 0
Private currencyPositivePattern
Type : number
Default value : 0
Private currencySymbol
Type : string
Default value : '$'
Private negativeSign
Type : string
Default value : '-'
Private numberDecimalDigits
Type : number
Default value : 2
Private numberDecimalSeparator
Type : string
Default value : '.'
Private numberGroupSeparator
Type : string
Default value : ','
Private numberGroupSizes
Type : number[]
Default value : [3]
Private numberNegativePattern
Type : number
Default value : 1
Private percentDecimalDigits
Type : number
Default value : 2
Private percentDecimalSeparator
Type : string
Default value : '.'
Private percentGroupSeparator
Type : string
Default value : ','
Private percentGroupSizes
Type : number[]
Default value : [3]
Private percentNegativePattern
Type : number
Default value : 1
Private percentPositivePattern
Type : number
Default value : 1
Private percentSymbol
Type : string
Default value : '%'

Methods

Public Clone
Clone()

Creates a copy of this object

Returns : NumberFormatInfo

{NumberFormatInfo}

Accessors

CurrencyDecimalDigits
getCurrencyDecimalDigits()

Currency decimal separator to use as separator for the decimals

Returns : number
setCurrencyDecimalDigits(v: number)
Parameters :
Name Type Optional
v number No
Returns : void
CurrencyDecimalSeparator
getCurrencyDecimalSeparator()

Currency decimal separator to use as separator for the decimals

Returns : string
setCurrencyDecimalSeparator(v: string)
Parameters :
Name Type Optional
v string No
Returns : void
CurrencyGroupSeparator
getCurrencyGroupSeparator()

Currency group separator to use for the groups to the left of the decimal

Returns : string
setCurrencyGroupSeparator(v: string)
Parameters :
Name Type Optional
v string No
Returns : void
CurrencyGroupSizes
getCurrencyGroupSizes()

Currency group sizes to use in each group to the left of the decimal

Returns : number[]
setCurrencyGroupSizes(v: number[])
Parameters :
Name Type Optional
v number[] No
Returns : void
CurrencyNegativePattern
getCurrencyNegativePattern()

Currency negative pattern to use when values are negative

Returns : number
setCurrencyNegativePattern(v: number)
Parameters :
Name Type Optional
v number No
Returns : void
CurrencyPositivePattern
getCurrencyPositivePattern()

Currency positive pattern to use when values are positive

Returns : number
setCurrencyPositivePattern(v: number)
Parameters :
Name Type Optional
v number No
Returns : void
CurrencySymbol
getCurrencySymbol()

Currency symbol

Returns : string
setCurrencySymbol(v: string)
Parameters :
Name Type Optional
v string No
Returns : void
NumberDecimalDigits
getNumberDecimalDigits()

Number of decimal characters

Returns : number
setNumberDecimalDigits(v: number)
Parameters :
Name Type Optional
v number No
Returns : void
NumberDecimalSeparator
getNumberDecimalSeparator()

String used as decimal separator

Returns : string
setNumberDecimalSeparator(v: string)
Parameters :
Name Type Optional
v string No
Returns : void
NumberGroupSeparator
getNumberGroupSeparator()

String used as thousands group separator

Returns : string
setNumberGroupSeparator(v: string)
Parameters :
Name Type Optional
v string No
Returns : void
NumberGroupSizes
getNumberGroupSizes()

Array containing the group sizes for thousands separator

Returns : number[]
setNumberGroupSizes(v: number[])
Parameters :
Name Type Optional
v number[] No
Returns : void
NumberNegativePattern
getNumberNegativePattern()

Pattern to use for negative numbers

Returns : number
setNumberNegativePattern(v: number)
Parameters :
Name Type Optional
v number No
Returns : void
NegativeSign
getNegativeSign()

String used to indicate the negative sign for numeric values

Returns : string
setNegativeSign(v: string)
Parameters :
Name Type Optional
v string No
Returns : void
PercentDecimalDigits
getPercentDecimalDigits()

Number of decimal digits to use when converting to percent

Returns : number
setPercentDecimalDigits(v: number)
Parameters :
Name Type Optional
v number No
Returns : void
PercentDecimalSeparator
getPercentDecimalSeparator()

String to use to separate the decimal part

Returns : string
setPercentDecimalSeparator(v: string)
Parameters :
Name Type Optional
v string No
Returns : void
PercentGroupSeparator
getPercentGroupSeparator()

String to use to separate the groups in the numeric part

Returns : string
setPercentGroupSeparator(v: string)
Parameters :
Name Type Optional
v string No
Returns : void
PercentGroupSizes
getPercentGroupSizes()

Group sizes to use to separate the numeric part

Returns : number[]
setPercentGroupSizes(v: number[])
Parameters :
Name Type Optional
v number[] No
Returns : void
PercentNegativePattern
getPercentNegativePattern()

Pattern to use when representing negative percent

Returns : number
setPercentNegativePattern(v: number)
Parameters :
Name Type Optional
v number No
Returns : void
PercentPositivePattern
getPercentPositivePattern()

Pattern to use when representing positive percent

Returns : number
setPercentPositivePattern(v: number)
Parameters :
Name Type Optional
v number No
Returns : void
PercentSymbol
getPercentSymbol()

Symbol to use when representing percent

Returns : string
setPercentSymbol(v: string)
Parameters :
Name Type Optional
v string No
Returns : void
export class DateTimeFormatInfo {
  private shortDatePattern = '';
  private fullDateTimePattern = '';
  private longDatePattern = '';
  private shortTimePattern = '';
  private longTimePattern = '';
  private monthDayPattern = '';
  private yearMonthPattern = '';
  private sortableDateTimePattern = '';
  private dayNames: string[] = [];
  private monthNames: string[] = [];

  /**
   *  Gets the current date time formatin information object
   *
   * @static
   * @return {*}  {DateTimeFormatInfo}
   * @memberof DateTimeFormatInfo
   * @wIgnore
   */
  public static GetCurrentInfo(): DateTimeFormatInfo {
    return GlobalizationHelper.Current.DateTimeFormat;
  }

  /**
   *  Short date format pattern
   *
   * @type {string}
   * @memberof DateTimeFormatInfo
   */
  public get ShortDatePattern(): string {
    return this.shortDatePattern;
  }
  public set ShortDatePattern(v: string) {
    this.shortDatePattern = v;
  }

  /**
   *  Full date and time format pattern
   *
   * @type {string}
   * @memberof DateTimeFormatInfo
   */
  public get FullDateTimePattern(): string {
    return this.fullDateTimePattern;
  }
  public set FullDateTimePattern(v: string) {
    this.fullDateTimePattern = v;
  }

  /**
   *  Long date format pattern
   *
   * @type {string}
   * @memberof DateTimeFormatInfo
   */
  public get LongDatePattern(): string {
    return this.longDatePattern;
  }
  public set LongDatePattern(v: string) {
    this.longDatePattern = v;
  }

  /**
   *  Short time pattern format
   *
   * @type {string}
   * @memberof DateTimeFormatInfo
   */
  public get ShortTimePattern(): string {
    return this.shortTimePattern;
  }
  public set ShortTimePattern(v: string) {
    this.shortTimePattern = v;
  }

  /**
   * Long time pattern
   *
   * @type {string}
   * @memberof DateTimeFormatInfo
   */
  public get LongTimePattern(): string {
    return this.longTimePattern;
  }
  public set LongTimePattern(v: string) {
    this.longTimePattern = v;
  }

  /**
   *  Mothn day pattern
   *
   * @type {string}
   * @memberof DateTimeFormatInfo
   */
  public get MonthDayPattern(): string {
    return this.monthDayPattern;
  }
  public set MonthDayPattern(v: string) {
    this.monthDayPattern = v;
  }

  /**
   *  Year month pattern
   *
   * @type {string}
   * @memberof DateTimeFormatInfo
   */
  public get YearMonthPattern(): string {
    return this.yearMonthPattern;
  }
  public set YearMonthPattern(v: string) {
    this.yearMonthPattern = v;
  }

  /**
   *  Sortable date time pattern
   *
   * @type {string}
   * @memberof DateTimeFormatInfo
   */
  public get SortableDateTimePattern(): string {
    return this.sortableDateTimePattern;
  }
  public set SortableDateTimePattern(v: string) {
    this.sortableDateTimePattern = v;
  }

  /**
   *  Names of the weekdays
   *
   * @type {string[]}
   * @memberof DateTimeFormatInfo
   */
  public get DayNames(): string[] {
    return this.dayNames;
  }
  public set DayNames(v: string[]) {
    this.dayNames = v;
  }

  /**
   * Creates an instance of DateTimeFormatInfo.
   * @memberof DateTimeFormatInfo
   */
  public constructor(localeId?: string) {
    this.ShortDatePattern = 'MM/dd/yyyy';
    this.FullDateTimePattern = 'dddd, MMMM d, yyyy h:mm:ss tt';
    this.LongDatePattern = 'dddd, MMMM d, yyyy';
    this.ShortTimePattern = 'h:mm tt';
    this.LongTimePattern = 'h:mm:ss tt';
    this.MonthDayPattern = 'MMMM d';
    this.YearMonthPattern = 'MMMM yyyy';
    this.SortableDateTimePattern = 'yyyy-MM-ddTHH:mm:ss';
    const localeToUse = localeId ?? 'default';

    this.dayNames = [];
    for (let i = 0; i < 7; i++) {
      this.dayNames.push(
        new Date(`2000/1/${2 + i}`).toLocaleDateString(localeToUse, {
          weekday: 'long',
        })
      );
    }
    this.monthNames = [];
    for (let i = 1; i < 13; i++) {
      this.monthNames.push(
        new Date(`2000/${i}/1`).toLocaleDateString(localeToUse, {
          month: 'long',
        })
      );
    }
  }

  /**
   *  Clones the current instance
   *
   * @return {*}  {DateTimeFormatInfo}
   * @memberof DateTimeFormatInfo
   */
  public Clone(): DateTimeFormatInfo {
    const result = new DateTimeFormatInfo();
    result.DayNames = this.DayNames;
    result.monthNames = this.monthNames;
    result.FullDateTimePattern = this.FullDateTimePattern;
    result.LongDatePattern = this.LongDatePattern;
    result.LongTimePattern = this.LongTimePattern;
    result.MonthDayPattern = this.MonthDayPattern;
    result.ShortDatePattern = this.ShortDatePattern;
    result.ShortTimePattern = this.ShortTimePattern;
    result.YearMonthPattern = this.YearMonthPattern;
    result.SortableDateTimePattern = this.SortableDateTimePattern;
    return result;
  }

  /**
   *  Gets the name of the given month
   *
   * @param {number} monthNumber number of the month between 1 and 12
   * @return {*}  {string} the name of the month
   * @memberof DateTimeFormatInfo
   */
  public GetMonthName(monthNumber: number): string {
    if (monthNumber > 0 && monthNumber < 13) {
      return this.monthNames[monthNumber - 1];
    } else {
      throw new Error('Invalid month number');
    }
  }
}

/**
 *  Numeric formats information
 *
 * @export
 * @class NumberFormatInfo
 * @wType System.Globalization.NumberFormatInfo
 * @wNetSupport
 */
export class NumberFormatInfo {
  private negativeSign: string = '-';
  private currencyDecimalDigits: number = 2;
  private currencyDecimalSeparator: string = '.';
  private currencyGroupSeparator: string = ',';
  private currencyGroupSizes: number[] = [3];
  private currencyNegativePattern: number = 0;
  private currencyPositivePattern: number = 0;
  private currencySymbol: string = '$';
  private numberDecimalDigits: number = 2;
  private numberDecimalSeparator: string = '.';
  private numberGroupSeparator: string = ',';
  private numberGroupSizes: number[] = [3];
  private numberNegativePattern: number = 1;
  private percentDecimalDigits: number = 2;
  private percentDecimalSeparator: string = '.';
  private percentGroupSeparator: string = ',';
  private percentGroupSizes: number[] = [3];
  private percentNegativePattern: number = 1;
  private percentPositivePattern: number = 1;
  private percentSymbol: string = '%';

  /**
   *  Currency decimal separator to use as separator for the decimals
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get CurrencyDecimalDigits(): number {
    return this.currencyDecimalDigits;
  }
  public set CurrencyDecimalDigits(v: number) {
    this.currencyDecimalDigits = v;
  }

  /**
   *  Currency decimal separator to use as separator for the decimals
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get CurrencyDecimalSeparator(): string {
    return this.currencyDecimalSeparator;
  }
  public set CurrencyDecimalSeparator(v: string) {
    this.currencyDecimalSeparator = v;
  }

  /**
   *  Currency group separator to use for the groups to the left of the decimal
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get CurrencyGroupSeparator(): string {
    return this.currencyGroupSeparator;
  }
  public set CurrencyGroupSeparator(v: string) {
    this.currencyGroupSeparator = v;
  }

  /**
   *  Currency group sizes to use in each group to the left of the decimal
   *
   * @type {number[]}
   * @memberof NumberFormatInfo
   */
  public get CurrencyGroupSizes(): number[] {
    return this.currencyGroupSizes;
  }
  public set CurrencyGroupSizes(v: number[]) {
    this.currencyGroupSizes = v;
  }

  /**
   *  Currency negative pattern to use when values are negative
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get CurrencyNegativePattern(): number {
    return this.currencyNegativePattern;
  }
  public set CurrencyNegativePattern(v: number) {
    this.currencyNegativePattern = v;
  }

  /**
   *  Currency positive pattern to use when values are positive
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get CurrencyPositivePattern(): number {
    return this.currencyPositivePattern;
  }
  public set CurrencyPositivePattern(v: number) {
    this.currencyPositivePattern = v;
  }

  /**
   *  Currency symbol
   *
   * @type {string}
   * @memberof NumberFormatInfo
   */
  public get CurrencySymbol(): string {
    return this.currencySymbol;
  }
  public set CurrencySymbol(v: string) {
    this.currencySymbol = v;
  }

  /**
   *  Number of decimal characters
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get NumberDecimalDigits(): number {
    return this.numberDecimalDigits;
  }
  public set NumberDecimalDigits(v: number) {
    this.numberDecimalDigits = v;
  }

  /**
   *  String used as decimal separator
   *
   * @type {string}
   * @memberof NumberFormatInfo
   */
  public get NumberDecimalSeparator(): string {
    return this.numberDecimalSeparator;
  }
  public set NumberDecimalSeparator(v: string) {
    this.numberDecimalSeparator = v;
  }

  /**
   *  String used as thousands group separator
   *
   * @type {string}
   * @memberof NumberFormatInfo
   */
  public get NumberGroupSeparator(): string {
    return this.numberGroupSeparator;
  }
  public set NumberGroupSeparator(v: string) {
    this.numberGroupSeparator = v;
  }

  /**
   *  Array containing the group sizes for thousands separator
   *
   * @type {number[]}
   * @memberof NumberFormatInfo
   */
  public get NumberGroupSizes(): number[] {
    return this.numberGroupSizes;
  }
  public set NumberGroupSizes(v: number[]) {
    this.numberGroupSizes = v;
  }

  /**
   *  Pattern to use for negative numbers
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get NumberNegativePattern(): number {
    return this.numberNegativePattern;
  }
  public set NumberNegativePattern(v: number) {
    this.numberNegativePattern = v;
  }

  /**
   *  String used to indicate the negative sign for numeric values
   *
   * @type {string}
   * @memberof NumberFormatInfo
   */
  public get NegativeSign(): string {
    return this.negativeSign;
  }
  public set NegativeSign(v: string) {
    this.negativeSign = v;
  }

  /**
   *  Number of decimal digits to use when converting to percent
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get PercentDecimalDigits(): number {
    return this.percentDecimalDigits;
  }
  public set PercentDecimalDigits(v: number) {
    this.percentDecimalDigits = v;
  }

  /**
   *  String to use to separate the decimal part
   *
   * @type {string}
   * @memberof NumberFormatInfo
   */
  public get PercentDecimalSeparator(): string {
    return this.percentDecimalSeparator;
  }
  public set PercentDecimalSeparator(v: string) {
    this.percentDecimalSeparator = v;
  }

  /**
   *  String to use to separate the groups in the numeric part
   *
   * @type {string}
   * @memberof NumberFormatInfo
   */
  public get PercentGroupSeparator(): string {
    return this.percentGroupSeparator;
  }
  public set PercentGroupSeparator(v: string) {
    this.percentGroupSeparator = v;
  }

  /**
   *  Group sizes to use to separate the numeric part
   *
   * @type {number[]}
   * @memberof NumberFormatInfo
   */
  public get PercentGroupSizes(): number[] {
    return this.percentGroupSizes;
  }
  public set PercentGroupSizes(v: number[]) {
    this.percentGroupSizes = v;
  }

  /**
   *  Pattern to use when representing negative percent
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get PercentNegativePattern(): number {
    return this.percentNegativePattern;
  }
  public set PercentNegativePattern(v: number) {
    this.percentNegativePattern = v;
  }

  /**
   *  Pattern to use when representing positive percent
   *
   * @type {number}
   * @memberof NumberFormatInfo
   */
  public get PercentPositivePattern(): number {
    return this.percentPositivePattern;
  }
  public set PercentPositivePattern(v: number) {
    this.percentPositivePattern = v;
  }

  /**
   *  Symbol to use when representing percent
   *
   * @type {string}
   * @memberof NumberFormatInfo
   */
  public get PercentSymbol(): string {
    return this.percentSymbol;
  }
  public set PercentSymbol(v: string) {
    this.percentSymbol = v;
  }

  /**
   * Creates an instance of NumberFormatInfo.
   * @memberof NumberFormatInfo
   */
  constructor() {}

  /**
   * Creates a copy of this object
   *
   * @return {*}  {NumberFormatInfo}
   * @memberof NumberFormatInfo
   */
  public Clone(): NumberFormatInfo {
    let result = new NumberFormatInfo();
    result.negativeSign = this.negativeSign;

    result.currencyDecimalDigits = this.currencyDecimalDigits;
    result.currencyDecimalSeparator = this.currencyDecimalSeparator;
    result.currencyGroupSeparator = this.currencyGroupSeparator;
    result.currencyGroupSizes = [...this.currencyGroupSizes];
    result.currencyNegativePattern = this.currencyNegativePattern;
    result.currencyPositivePattern = this.currencyPositivePattern;
    result.currencySymbol = this.currencySymbol;

    result.numberDecimalDigits = this.numberDecimalDigits;
    result.numberDecimalSeparator = this.numberDecimalSeparator;
    result.numberGroupSeparator = this.numberGroupSeparator;
    result.numberGroupSizes = [...this.numberGroupSizes];
    result.numberNegativePattern = this.numberNegativePattern;

    result.percentDecimalDigits = this.percentDecimalDigits;
    result.percentDecimalSeparator = this.percentDecimalSeparator;
    result.percentGroupSeparator = this.percentGroupSeparator;
    result.percentGroupSizes = [...this.percentGroupSizes];
    result.percentNegativePattern = this.percentNegativePattern;
    result.percentPositivePattern = this.percentPositivePattern;
    result.percentSymbol = this.percentSymbol;

    return result;
  }
}

/**
 *  Comparison information
 *
 * @export
 * @class CompareInfo
 * @wType System.Globalization.CompareInfo
 * @wNetSupport
 */
export class CompareInfo {
  IsPrefix(str: string, prefix: string): boolean {
    return str.startsWith(prefix);
  }
}

/**
 *  Helper for globalization information
 *
 * @export
 * @class GlobalizationHelper
 * @wType System.Globalization.CultureInfo
 * @wNetSupport
 */
export class GlobalizationHelper {
  /**
   *  Gets the current instance of the GlobalizationHelper
   *
   * @static
   * @type {GlobalizationHelper}
   * @memberof GlobalizationHelper
   * @wProperty CurrentCulture, CurrentUICulture
   */
  public static Current: GlobalizationHelper = new GlobalizationHelper();

  /**
   *  Gets the current instance of the invariant Globalization helper
   *
   * @static
   * @type {GlobalizationHelper}
   * @memberof GlobalizationHelper
   * @wProperty InvariantCulture
   */
  public static Invariant: GlobalizationHelper = new GlobalizationHelper();

  /**
   *  Id of the locale of this instance
   *
   * @type {string}
   * @memberof GlobalizationHelper
   */
  public localeId: string = 'default';

  /**
   * Comparison object
   *
   * @memberof GlobalizationHelper
   */
  public CompareInfo = new CompareInfo();

  /**
   *  Date and time format information
   *
   * @memberof GlobalizationHelper
   */
  public DateTimeFormat: DateTimeFormatInfo;

  /**
   *  Numeric format information
   *
   * @memberof GlobalizationHelper
   */
  public NumberFormat = new NumberFormatInfo();

  constructor(localeId?: string) {
    this.localeId = localeId ?? 'default';
    this.DateTimeFormat = new DateTimeFormatInfo(localeId);
  }

  /**
   *  Creates a copy of the current object
   *
   * @return {*}  {GlobalizationHelper}
   * @memberof GlobalizationHelper
   */
  public Clone(): GlobalizationHelper {
    let copy = new GlobalizationHelper(this.localeId);
    copy.CompareInfo = this.CompareInfo;
    copy.DateTimeFormat = this.DateTimeFormat.Clone();
    copy.NumberFormat = this.NumberFormat.Clone();
    return copy;
  }
}

result-matching ""

    No results matching ""