Senin, 27 Februari 2017

AX : Date2string AX 2012

static void date2StringTest(Args _args)
{
    str dateStrYMD = '2013-01-08';
    str dateStrMYD = '01-2013-08';
    str dateStrMDY = '01-08-2013';
    str dateStrDMY = '08-01-2013';
    str dateStrYMD2y = '13-01-08'; // two digit year
    str dateStrYMD1m = '2013-1-08'; // 1 digit month
    str dateStrYMDinv = '2013-14-08'; // invalid month
    str dateStrYMDslsh = '2013/1/08'; // Slash instead of dash
    str zeroResultStr = 'INVALID and will be 0';
    int i;

    // Note that the second parameter to the str2Date field is 3 numbers which must be a
    // combination using 1, 2, and 3 where 1 = day, 2 = month, and 3 = year
    // For example 231 would be MM-YYYY-DD, and 321 would be YYYY-MM-YY

    // Year Month Day test
    info (strFmt("----Start YMD test for %1----", dateStrYMD));
    info (strFmt("1. YMD - str2Date('%1', 321) - result: %2", dateStrYMD, str2Date(dateStrYMD, 321)));
    info (strFmt("2. YMD - str2Date('%1', 231) - result: %2", dateStrYMD, str2Date(dateStrYMD, 231)));
    info (strFmt("3. YMD - str2Date('%1', 213) - result: %2", dateStrYMD, str2Date(dateStrYMD, 213)));
    info (strFmt("4. YMD - str2Date('%1', 123) - result: %2", dateStrYMD, str2Date(dateStrYMD, 123)));
    info ("");

    // Month Year Day test
    info (strFmt("----Start MYD test for %1----", dateStrMYD));
    info (strFmt("5. MYD - str2Date('%1', 321) - result: %2", dateStrMYD, str2Date(dateStrMYD, 321)));
    info (strFmt("6. MYD - str2Date('%1', 231) - result: %2", dateStrMYD, str2Date(dateStrMYD, 231)));
    info (strFmt("7. MYD - str2Date('%1', 213) - result: %2", dateStrMYD, str2Date(dateStrMYD, 213)));
    info (strFmt("8. MYD - str2Date('%1', 123) - result: %2", dateStrMYD, str2Date(dateStrMYD, 123)));
    info ("");

    // Month Day Year test
    info (strFmt("----Start MDY test for %1----", dateStrMDY));
    info (strFmt("9.  MDY - str2Date('%1', 321) - result: %2", dateStrMDY, str2Date(dateStrMDY, 321)));
    info (strFmt("10. MDY - str2Date('%1', 231) - result: %2", dateStrMDY, str2Date(dateStrMDY, 231)));
    info (strFmt("11. MDY - str2Date('%1', 213) - result: %2", dateStrMDY, str2Date(dateStrMDY, 213)));
    info (strFmt("12. MDY - str2Date('%1', 123) - result: %2", dateStrMDY, str2Date(dateStrMDY, 123)));
    info ("");

    // Day Month Year test
    info (strFmt("----Start DMY test for %1----", dateStrDMY));
    info (strFmt("13. DMY - str2Date('%1', 321) - result: %2", dateStrDMY, str2Date(dateStrDMY, 321)));
    info (strFmt("14. DMY - str2Date('%1', 231) - result: %2", dateStrDMY, str2Date(dateStrDMY, 231)));
    info (strFmt("15. DMY - str2Date('%1', 213) - result: %2", dateStrDMY, str2Date(dateStrDMY, 213)));
    info (strFmt("16. DMY - str2Date('%1', 123) - result: %2", dateStrDMY, str2Date(dateStrDMY, 123)));
    info ("");

    // Other scenarios
    info ("----START OTHER SCENARIOS----");
    info (strFmt("17. YMD using %1 which only has 2 digits for the year (e.g. 13 instead of 2013) -            result: %2", dateStrYMD2y, str2Date(dateStrYMD2y, 321))); // 2 digit year
    info (strFmt("18. YMD using %1 which only has 1 digit for the month (e.g. 1 instead of 01) -               result: %2", dateStrYMD1m, str2Date(dateStrYMD1m, 321))); // 1 digit month
    info (strFmt("19. YMD using %1 which has an invalid numbe for the month (e.g. 14 is greater than 12) - result: %2", dateStrYMDInv, str2Date(dateStrYMDInv, 321))); // invalid month
    info (strFmt("20. YMD using %1 which has a slash instead of a dash (e.g. 2013/01/08 instead of 2013-01-08) - result: %2", dateStrYMDslsh, str2Date(dateStrYMDslsh, 321))); // different divider
}

Tidak ada komentar:

Posting Komentar