Define format culture

Posted by: pedro.moraes on 5 July 2023, 2:13 pm EST

  • Posted 5 July 2023, 2:13 pm EST

    Hello,

    I use some predefined culture files. The texts are correct but the formatting is wrong.

    For example

    Putting the date 7/5/2023 and selecting the long date, using the culture I created for Brazil, it should stay:

    quarta-feira, 5 de julho de 2023 but stayed quarta-feira, julho 05, 2023

    import * as GC from '@grapecity/spread-sheets';
    const cultureInfo = new GC.Spread.Common.CultureInfo();
    cultureInfo.id = 1;
    cultureInfo.displayName = 'Portuguese (Brazil)';
    cultureInfo.name = function () {
      return 'pt-BR';
    };
    cultureInfo.NumberFormat.currencyDecimalSeparator = ',';
    cultureInfo.NumberFormat.currencyGroupSeparator = '.';
    cultureInfo.NumberFormat.currencySymbol = 'R$';
    cultureInfo.NumberFormat.numberDecimalSeparator = ',';
    cultureInfo.NumberFormat.numberGroupSeparator = '.';
    cultureInfo.NumberFormat.listSeparator = ';';
    cultureInfo.NumberFormat.arrayListSeparator = '\\';
    cultureInfo.NumberFormat.arrayGroupSeparator = ';';
    cultureInfo.DateTimeFormat.abbreviatedDayNames = ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'];
    cultureInfo.DateTimeFormat.abbreviatedMonthGenitiveNames = [
      'jan',
      'fev',
      'mar',
      'abr',
      'mai',
      'jun',
      'jul',
      'ago',
      'set',
      'out',
      'nov',
      'dez',
      '',
    ];
    cultureInfo.DateTimeFormat.abbreviatedMonthNames = ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez', ''];
    cultureInfo.DateTimeFormat.amDesignator = 'AM';
    cultureInfo.DateTimeFormat.dayNames = ['domingo', 'segunda-feira', 'terça-feira', 'quarta-feira', 'quinta-feira', 'sexta-feira', 'sábado'];
    cultureInfo.DateTimeFormat.fullDateTimePattern = "dddd, d 'de' MMMM 'de' yyyy HH:mm:ss";
    cultureInfo.DateTimeFormat.longDatePattern = "dddd, d 'de' MMMM 'de' yyyy";
    cultureInfo.DateTimeFormat.longTimePattern = 'HH:mm:ss';
    cultureInfo.DateTimeFormat.monthDayPattern = "d 'de' MMMM";
    cultureInfo.DateTimeFormat.monthGenitiveNames = [
      'janeiro',
      'fevereiro',
      'março',
      'abril',
      'maio',
      'junho',
      'julho',
      'agosto',
      'setembro',
      'outubro',
      'novembro',
      'dezembro',
      '',
    ];
    cultureInfo.DateTimeFormat.monthNames = [
      'janeiro',
      'fevereiro',
      'março',
      'abril',
      'maio',
      'junho',
      'julho',
      'agosto',
      'setembro',
      'outubro',
      'novembro',
      'dezembro',
      '',
    ];
    cultureInfo.DateTimeFormat.pmDesignator = 'PM';
    cultureInfo.DateTimeFormat.shortDatePattern = 'dd/MM/yyyy';
    cultureInfo.DateTimeFormat.shortTimePattern = 'HH:mm';
    cultureInfo.DateTimeFormat.yearMonthPattern = "MMMM 'de' yyyy";
    export default cultureInfo;
    import culturePT from './../../constants/culture/pt-BR';
    ...
     GC.Spread.Common.CultureManager.addCultureInfo(`${culturePT.name()}-ACCY`, culturePT);
        GC.Spread.Common.CultureManager.culture(`${culturePT.name()}-ACCY`);
  • Posted 6 July 2023, 12:30 pm EST

    Hello,

    Please note that when you enter the value in 7/5/2023 then the value is formatted as per the shortDatePattern of cultureInfo.DateTimeFormat.shortDatePattern. So, you need to set the cultureInfo.DateTimeFormat.shortDatePattern property to ‘dddd, d “de” MMMM “de” yyyy’

    Similarly, you can also modify the other properties of the culture to specify your custom setttings.

    Please refer to the code snippet and attached sample.

    
    cultureInfo.DateTimeFormat.shortDatePattern = 'dddd, d "de" MMMM "de" yyyy';

    Sample: https://jscodemine.grapecity.com/share/3wi38uBirU_2LfZvc_uqsw/?IsEmbed=false&Theme=Unset&PreviewDirection=0&IsEditorShow=true&IsExplorerShow=true&IsPreviewShow=true&IsConsoleShow=true&IsRunBTNShow=false&IsResetBTNShow=false&IsOpenInCodemineBTNShow=false&PanelWidth=20&PanelWidth=50&PanelWidth=30&defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Findex.html"}

    Please let us know if you need further assistance.

    Doc reference:

    IDateTimeFormat.shortDatePattern: https://www.grapecity.com/spreadjs/api/v16/interfaces/GC.Spread.Common.IDateTimeFormat#shortdatepattern

    Regards,

    Ankit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels