Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.core.simpletypes.temporal;

import org.litesoft.commonfoundation.typeutils.gregorian.*;

import junit.framework.*;

public class DateFormatTest extends TestCase
{
    public static TestSuite suite()
    {
        return new TestSuite( DateFormatTest.class );
    }

    public DateFormatTest( String name )
    {
        super( name );
    }

    public static void main( String[] args )
    {
        junit.textui.TestRunner.run( suite() );
    }

    public void test_FormatToDateResAndFieldOrder()
    {
        chkRT( "y", DateRes.ToYEAR );
        chkRT( "yM", DateRes.ToMONTH );
        chkRT( "yMd", DateRes.ToDAY );
    }

    private void chkRT( String pFormatAndFieldOrder, DateRes pDateResExpected )
    {
        DateFormat zFormat = new DateFormat( pFormatAndFieldOrder );
        assertEquals( pDateResExpected, zFormat.getDateRes() );
    }

    public void test_ContructorsAndToString()
            throws Exception
    {
        chkYMD( "dd MMM yyyy", "dMy", 2004, 2, 29, "29 Feb 2004" ); // Leap Day
        chkYMD( "dd MMM yyyy", "dMy", 2000, 2, 29, "29 Feb 2000" ); // exception-exception Leap Day

        chkYMD( "dd MMM yyyy", "dMy", 1957, 1, 4, "04 Jan 1957" );

        chkYMD( "MM/dd/yy", "Mdy", 1957, 1, 4, "01/04/57" );
        chkYMD( "init y/M/d fini", "yMd", 1957, 1, 4, "init 1957/1/4 fini" );
        chkYMD( "dMMM", "dM", 1957, 1, 4, "4Jan" );
        chkYMD( "dMMMyy", "dMy", 1957, 1, 4, "4Jan57" );
        chkYMD( "dMMMyy", "dMy", 1957, 1, 4, "4Jan57" );
        chkYMD( "d MMMM y", "dMy", 1957, 1, 4, "4 January 1957" );
        chkYMD( "MMMM d, y", "Mdy", 1957, 1, 4, "January 4, 1957" );
        chkYMD( "(M/d/y) MMMM d", "Mdy", 1957, 1, 4, "(1/4/1957) January 4" );
        chkYMD( "(M/d/y) ddMMM", "Mdy", 1957, 1, 4, "(1/4/1957) 04Jan" );

        chkYM( "MMMMMM y", "My", 1957, 1, "January 1957" );

        chkY( "yy", "y", 1996, "96" );
        chkY( "/yy", "y", 1996, "/96" );
        chkY( "/ y:", "y", 1996, "/ 1996:" );
        chkY( "/ yyy:", "y", 1996, "/ 1996:" );
    }

    private void chkYMD( String pDateFormat, String pFieldOrder, int pYear, int pMonth, int pDay, String pToString )
    {
        chkYMD( new DateFormat( pDateFormat ), new CalendarYMD( pYear, pMonth, pDay ), pToString, pFieldOrder, pYear, pMonth, pDay );
    }

    private void chkYM( String pDateFormat, String pFieldOrder, int pYear, int pMonth, String pToString )
    {
        chkYM( new DateFormat( pDateFormat ), new CalendarYM( pYear, pMonth ), pToString, pFieldOrder, pYear, pMonth );
    }

    private void chkY( String pDateFormat, String pFieldOrder, int pYear, String pToString )
    {
        chkY( new DateFormat( pDateFormat ), new CalendarY( pYear ), pToString, pFieldOrder, pYear );
    }

    private void chkYMD( DateFormat pFormat, CalendarAccessorYMD pDate, String pToString, String pFieldOrder, int pYear, int pMonth, int pDay )
    {
        assertEquals( pFieldOrder, pFormat.getFieldOrder() );
        assertEquals( "Day", pDay, pDate.getDay() );
        chkYMcommon( pFormat, pDate, pToString, pYear, pMonth );
    }

    private void chkYM( DateFormat pFormat, CalendarAccessorYM pDate, String pToString, String pFieldOrder, int pYear, int pMonth )
    {
        assertEquals( pFieldOrder, pFormat.getFieldOrder() );
        chkYMcommon( pFormat, pDate, pToString, pYear, pMonth );
    }

    private void chkY( DateFormat pFormat, CalendarAccessorY pDate, String pToString, String pFieldOrder, int pYear )
    {
        assertEquals( pFieldOrder, pFormat.getFieldOrder() );
        chkYcommon( pFormat, pDate, pToString, pYear );
    }

    private void chkYMcommon( DateFormat pFormat, CalendarAccessorYM pDate, String pToString, int pYear, int pMonth )
    {
        assertEquals( "Month", pMonth, pDate.getMonth() );
        chkYcommon( pFormat, pDate, pToString, pYear );
    }

    private void chkYcommon( DateFormat pFormat, CalendarAccessorY pDate, String pToString, int pYear )
    {
        assertEquals( "Year", pYear, pDate.getYear() );
        assertEquals( pToString, pFormat.format( pDate ) );
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/tests/org/litesoft/core/simpletypes/temporal/DateFormatTest.java

Diff revisions: vs.
Revision Author Commited Message
942 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 23:41:46 +0000

Extracting commonfoundation

869 GeorgeS picture GeorgeS Mon 26 Nov, 2012 01:33:04 +0000