Показать сообщение отдельно
Старый 03.11.2017, 00:23   #295  
kashperuk is offline
kashperuk
Участник
Аватар для kashperuk
MCBMSS
Соотечественники
Сотрудники Microsoft Dynamics
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии 2011
Лучший по профессии 2009
 
4,361 / 2084 (78) +++++++++
Регистрация: 30.05.2004
Адрес: Atlanta, GA, USA
Цитата:
Сообщение от Slava Chernenko Посмотреть сообщение
X++:
static void yearDiff_test(Args _args)
{;
// AX 2009 5.0.1500.4570

    info(strfmt('%1', yearDiff(28\2\2017, 28\2\1976)));   // returns 41 - OK
    info(strfmt('%1', yearDiff(1\3\2017,  29\2\1976)));    // returns 41 - OK
    info(strfmt('%1', yearDiff(28\2\2017, 29\2\1976)));   // returns 40 - arguable
    info(strfmt('%1', yearDiff(1\3\2017,   1\3\1976)));     // returns 40 - wtf?
    info(strfmt('%1', yearDiff(2\3\2117,   1\3\1976)));     // returns 140 - WTF!?
}
Попробуй починить?

X++:
    static int yearDiff(date d1, date d2)
    {
        date boundary;
        int offset;

        if ( d1 < d2)
        {
            boundary = mkDate(dayOfMth(d1), mthOfYr(d1), year(d2));
            offset = (d2 - boundary) < 0 ? -1 : 0;
        }
        else
        {
            boundary = mkDate(dayOfMth(d2), mthOfYr(d2), year(d1));
            offset = (d1 - boundary) < 0 ? 1 : 0;
        }

        return year(d1) - year (d2) - offset ;
    }