1 (edited by apmuthu 09/11/2012 04:50:30 pm)

Topic: Date Format Modification to dd-Mmm-YYYY

A fourth date format like 31-Aug-2012 to be represented in the config.php as DDMMMYYYY or DDMmmYYYY or if only 8 chars are allowed then DDmmYYYY would be nice:

Some errors with form field names like TransToDate and OrdersToDate have been experienced when the following 4 files were looked into for minor changes:

pdf_report.inc
excel_report.inc
ui_view.inc
date_functions.inc

In fact the last file above was attempted to be modified in 3 places in vain with:

1.

return $day.$sep.date('M', $year.$month.$day).$sep.$year;

2.

elseif (strlen($date_) == 9)
    {
        if ($how == 3) {
            $day = substr($date_,0,2);
            $month = date('m', strtotime(substr($date_,3,3)));
            $year = substr($date_,7,4);
        } else return 0;
    }

3.

        elseif ($how == 2) // YYYYMMDD
        list($year, $month, $day) = explode($sep, $date_);
    else // $how == 3, DDMmmYYYY
        list($year, $month, $day) = explode($sep, date('Y-m-d', strtotime($date_)));

Re: Date Format Modification to dd-Mmm-YYYY

What about integration with calendar?

Re: Date Format Modification to dd-Mmm-YYYY

Oh yes, that too! It was in fact the calendar that tripped me several times and continues to do so making me put off such investigation for some later date.....

We need to watch out for converting twice!

Is such a feature fulfillment on the cards in v2.3.x itself?

Re: Date Format Modification to dd-Mmm-YYYY

No, nor it is planned in 2.4. The only changes in date support are planned in next minor release, and you can download them from stable mercurial branch. The changes hopefully make manual date field edition less painfull using defaults for month/year.
But if you would like to contribute complete implementation for the proposed new date format, we can integrate it even in 2.3.x.
Janusz

5 (edited by apmuthu 09/10/2012 03:11:38 am)

Re: Date Format Modification to dd-Mmm-YYYY

Thanks for the info Janusz. Please direct me to where you have a Roadmap listed.

Will work on this feature when time permits as it needs a complete implementation.  This is the preferred date format in ASEAN countries what with the EU/US confusion on the date score...especially for CPAs who need to cater to clients across the globe and have "unambiguous" reports.

We need to cull out all instances of
1. Date Display
2. Date Form Fields
3. Date Picker (through wrapper function)
4. Date Picker (any unwrapped)
5. Date field computation
6. Date in SQL unabstracted

Any inputs here will help make for a smooth integration without catastrophic suprises.

6 (edited by apmuthu 09/11/2012 02:58:29 pm)

Re: Date Format Modification to dd-Mmm-YYYY

Proposed changes for additional date format.

File: config.php / config.default.php
Replace Line 139:
    $dateformats     = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD");
With:
    $dateformats     = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD", "DDMmmYYYY");

Correct "defalt" to "default" in commented line 143.

File: includes/date_functions.inc

1.
Replace lines 38-39:
    else
        return $year.$sep.$month.$sep.$day;
With:
    elseif ($how == 2)
        return $year.$sep.$month.$sep.$day;
    else
        return $day.$sep.date('M', $year.$month.$day).$sep.$year;

2. Altered fragment in function is_date($date_)

    elseif (strlen($date_) == 8)
    {
        if ($how == 3) // So as not to affect Jalali processing
        {
            $day = substr($date_,0,1);
            $month = date('m', strtotime(substr($date_,1,3)));
            $year = substr($date_,4,4);
        }
        elseif ($how == 0)
        {
            $day = substr($date_,2,2);
            $month = substr($date_,0,2);
            $year = substr($date_,4,4);
        } 
        elseif ($how == 1)
        {
            $day = substr($date_,0,2);
            $month = substr($date_,2,2);
            $year = substr($date_,4,4);
        } 
        else
        {
            $day = substr($date_,6,2);
            $month = substr($date_,4,2);
            $year = substr($date_,0,4);
        }
    }
    elseif (strlen($date_) == 9)
    {
        if ($how == 3)
        {
            $day = substr($date_,0,2);
            $month = date('m', strtotime(substr($date_,2,3)));
            $year = substr($date_,5,4);
        }
        else
            return 0;
    }

3. Altered fragment in function sql2date[$date_)

    // Split up the date by the separator based on "how" to split it
    if ($how == 0) // MMDDYYYY
        list($month, $day, $year) = explode($sep, $date_);
    elseif ($how == 1) // DDMMYYYY
        list($day, $month, $year) = explode($sep, $date_);
    elseif ($how == 2) // YYYYMMDD
        list($year, $month, $day) = explode($sep, $date_);
    elseif ($how == 3) // DDMmmYYYY
        list($year, $month, $day) = explode($sep, date('Y-m-d', strtotime($date_)));
    else
        return "";

7 (edited by apmuthu 09/11/2012 04:31:28 pm)

Re: Date Format Modification to dd-Mmm-YYYY

Additional places that need to be modified will be the date picker in the files

includes/ui/ui_input.inc (function date_cells)
and
includes/ui/ui_view.inc (function get_js_date_picker)

The insertion places in function get_js_date_picker would be:
At line 842

    $monthst = array(_("Jan"),_("Feb"),_("Mar"),_("Apr"),_("May"),_("Jun"),_("Jul"),_("Aug"),_("Sep"),_("Oct"),_("Nov"),_("Dec"));

and in the js string at line 922

  var monthst = ['$monthst[0]','$monthst[1]','$monthst[2]','$monthst[3]','$monthst[4]','$monthst[5]','$monthst[6]','$monthst[7]','$monthst[8]','$monthst[9]','$monthst[10]','$monthst[11]'];

Lines around 1043 can now be altered to:

    if ($how == 0)
        $js .= "
      var dateString = month+'$sep'+day+'$sep'+year;
";
    else if ($how == 1)
        $js .= "
      var dateString = day+'$sep'+month+'$sep'+year;
";
    else if ($how == 2)
        $js .= "
      var dateString = year+'$sep'+month+'$sep'+day;
";
    else // ($how == 3)
        $js .= "
      var dateString = year+'$sep'+monthst[month-1]+'$sep'+day;
";

Lines around 1180 can now be altered to:

    if ($how == 3)
        $js .= "
        selectedDay = parseInt(dateParts[0],10);
        selectedMonth = monthst.indexOf(dateParts[1])+1;
        selectedYear = parseInt(dateParts[2],10);
";
    else if ($how == 0)
        $js .= "
        selectedMonth = parseInt(dateParts[0],10);
        selectedDay = parseInt(dateParts[1],10);
        selectedYear = parseInt(dateParts[2],10);
";
    else if ($how == 1)
        $js .= "
        selectedDay = parseInt(dateParts[0],10);
        selectedMonth = parseInt(dateParts[1],10);
        selectedYear = parseInt(dateParts[2],10);
";
    else
        $js .= "
        selectedYear = parseInt(dateParts[0],10);
        selectedMonth = parseInt(dateParts[1],10);
        selectedDay = parseInt(dateParts[2],10);
";

It still does not work fully........

8 (edited by apmuthu 09/11/2012 04:49:12 pm)

Re: Date Format Modification to dd-Mmm-YYYY

Ref Code:
date_cells(_("From:"), 'AfterDate', '', null, -30);

The html output in FF 15.0.1 for an incorrect display for this format that now shows for one field is:

<input 
    autocomplete="off" 
    _last_val="2012-07-13" 
    name="AfterDate" 
    class="date" 
    size="10" 
    maxlength="12" 
    value="2012-07-13" 
    type="text"> 
<a 
    tabindex="-1" 
    href="javascript:date_picker(document.getElementsByName('AfterDate')[0]);">    
<img 
    src="../../themes/default/images/cal.gif" 
    alt="Click Here to Pick up the date" 
    border="0" 
    height="16" 
    width="16">
</a>

Ref Code:
date_cells(_("To:"), 'BeforeDate');

The html output in FF 15.0.1 for a correct initial display field (but not working input function) would be like:

<input 
    autocomplete="off" 
    _last_val="12-Aug-2012" 
    name="BeforeDate" 
    class="date" 
    size="10" 
    maxlength="12" 
    value="12-Aug-2012" 
    type="text"> 
<a 
    tabindex="-1" 
    href="javascript:date_picker(document.getElementsByName('BeforeDate')[0]);">    
<img 
    src="../../themes/default/images/cal.gif" 
    alt="Click Here to Pick up the date" 
    border="0" 
    height="16" 
    width="16">
</a>

The initial input size value of 10 may need to become 11 for this format....

The parameters for the functions date_cells and date_row are same and for reference are:

$label, 
$name, 
$title = null, 
$check=null, 
$inc_days=0, 
$inc_months=0, 
$inc_years=0, 
$params=null, 
$submit_on_change=false

9 (edited by apmuthu 09/11/2012 06:41:56 pm)

Re: Date Format Modification to dd-Mmm-YYYY

Anyone wishing to carry on this development can take the modified and unmodified files (based on FA v2.3.11+ Mercurial changeset 3053) altered here from:

http://www.apmuthu.com/bugfixes/fac-dev … format.zip

No way to upload files here!

JS Tute

includes/ui/simple_crud_class.inc has some functions with no change in formatting dates - maybe need to use them - _format_output and _format_input

Re: Date Format Modification to dd-Mmm-YYYY

This looks promissing, Amuthu. But let it mature a bit, before we include it in FA core. Maybe we need more formatting, like Jan 06 2012 or 2012 Jan 06. I don't know how needed this is, but I understand that the Asian Countries use this format a lot.
Letting it be world wide, we only need to replace the month digits with the short month name.

I am positive to this, just wanting it to mature a bit.

/Joe

11 (edited by apmuthu 09/12/2012 05:30:57 pm)

Re: Date Format Modification to dd-Mmm-YYYY

The above does NOT WORK at all. There is no question of including it for now. I am in the process of digging into what all code is getting affected.

The date picker does not work at all correctly for this feature choice as of now.

This is only a preliminary delving into the mire that the code currently is.

Re: Date Format Modification to dd-Mmm-YYYY

This is ok, Apmuthu. Please continue delving into this formatting. As this can always be implementied during a minor release, we are not in a hurry.

Joe

Re: Date Format Modification to dd-Mmm-YYYY

Apmuthu, I just got some spare-time and have implemented the new Mmm formatting for all the former date formats.

It was reasonaly simple to do, because I initially created the date_picker and the date_functions.

I am just making regorious testing to avoid side-effects, but haven't found any yet. But I am continuing a bit.

After that I will commit it to HG repository.

/Joe

Re: Date Format Modification to dd-Mmm-YYYY

Wow! That's great. You're the fastest in updating the repo!

Re: Date Format Modification to dd-Mmm-YYYY

This has now been pushed to HG repository.

Please be aware that when changing date format and/or date separator, that you may need to refresh the page several times to let the js script files, inserts.js and date_picker.js to be copied to /company/X/js_cashe folder where X is the company number.

/Joe

16 (edited by apmuthu 10/03/2012 07:10:06 am)

Re: Date Format Modification to dd-Mmm-YYYY

Alternatively, it should suffice to delete the said js files from each /company/X/js_cache folder.

Well done Joe!

Unrelated aside:

Bugfixes 1809-12 pertaining to unstable became marked as access denied in Mantis. Bugfix 1785 is still awaiting inclusion. (Role Elevation from reporter to developer in Mantis has not alleviated the Access denied status for following up on the said Bugs)

Re: Date Format Modification to dd-Mmm-YYYY

Please be patient a little while, apmuthu.

Awaiting Janusz approval to move FrontAccounting Next (Private) to FrontAccounting 2.4.

/Joe

Re: Date Format Modification to dd-Mmm-YYYY

Have bundled the consolidated unstable branch sql bugfix to help Janusz incorporate them easily - both changed files and patches.

Re: Date Format Modification to dd-Mmm-YYYY

Hg unstable branch has been updated. Thank you Apmuthu.
Janusz