Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-14896

Offer APIs to get XWiki's defined+default date formats

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 8.4
    • Fix Version/s: None
    • Component/s: Old Core
    • Labels:
      None
    • Difficulty:
      Unknown
    • Similar issues:

      Description

      This is needed for XWIKI-14894 for example.

      Right now it's hardcoded in XWiki.formatDate():

          public String formatDate(Date date, String format, XWikiContext context)
          {
              if (date == null) {
                  return "";
              }
              String xformat = format;
              String defaultFormat = "yyyy/MM/dd HH:mm";
      
              if (format == null) {
                  xformat = getXWikiPreference("dateformat", defaultFormat, context);
              }
      ...
      

      For now I'm proposing to add 2 new methods:

          /**
           * @return the default format used by XWiki for dates when the user hasn't configured a format
           * @since 9.11RC1
           */
          @Unstable
          public String getDefaultDateFormat()
          {
              return DEFAULT_DATE_FORMAT;
          }
      
          /**
           * @return the format used by XWiki for dates
           * @since 9.11RC1
           */
          @Unstable
          public String getDateFormat(XWikiContext context)
          {
              return getXWikiPreference("dateformat", getDefaultDateFormat(), context);
          }
      

      Note that in the future we'll need a better place. One idea would be add those methods in CoreConfiguration.

      Also note that we'll need a scripting API in the future. For example I noticed this in macros.vm:

      <input type="text" data-type="date" data-dateformat='$escapetool.html($xwiki.getXWikiPreference("dateformat",
                        "yyyy/MM/dd HH:mm"))' #if("$!colprop.size" != '') size="${colprop.size}"
                        title="$escapetool.xml($services.localization.render('platform.livetable.filtersTitle',
                        [$services.localization.render("${transprefix}${colname}")]))"#end />
      

      Right now AFAIK we don't a "core" ScriptService to expose configuration values. Right?

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vmassol Vincent Massol
              Reporter:
              vmassol Vincent Massol
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: