Subversion Repository Public Repository

litesoft

Diff Revisions 862 vs 864 for /trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/CalendarYM.java

Diff revisions: vs.
  @@ -3,13 +3,12 @@
3 3 import org.litesoft.core.*;
4 4
5 5 /**
6 - * A partial date that acts as a sort of proxy for a java.util.Date (burying the deprecated method use) providing
7 - * varying levels of resolution based on the DateRes.
6 + * A Calendar Year & Month, or partial "date" with resolution of Year and Month ("Wall" relative).
8 7 * <p/>
9 8 * Note: This class supports Gregorian dates only and has no concept of time or TimeZones. As such when working with
10 9 * Java Util Date(s) (or it's descendants) the local (or "Wall") date is all that is considered!
11 10 */
12 - public final class CalendarYM extends AbstractCalendarYM<CalendarYM> implements SQLdateable
11 + public final class CalendarYM extends AbstractCalendarYM<CalendarYM, AbstractCalendarYM.Mutable> implements SQLdateable
13 12 {
14 13 private static final long serialVersionUID = 1L;
15 14
  @@ -41,23 +40,19 @@
41 40 return YearMonthFormatAccessor.get().format( this );
42 41 }
43 42
44 - public static String toString( CalendarYM pDate )
43 + public static String toString( CalendarYM pCalendar )
45 44 {
46 - return (pDate != null) ? pDate.toString() : null;
45 + return (pCalendar != null) ? pCalendar.toString() : null;
47 46 }
48 47
49 - public static String toYM( CalendarYM pFromYM )
48 + public static String toYM( CalendarYM pCalendar )
50 49 {
51 - return (pFromYM != null) ? pFromYM.toYM() : null;
50 + return (pCalendar != null) ? pCalendar.toYM() : null;
52 51 }
53 52
54 53 public String toYM()
55 54 {
56 - StringBuilder sb = new StringBuilder();
57 - yyyy_Chunk.appendYearTo( this, sb );
58 - sb.append( '/' );
59 - MM_Chunk.appendMonthTo( this, sb );
60 - return sb.toString();
55 + return formatSortableDisplayFormYM( this, new StringBuilder() ).toString();
61 56 }
62 57
63 58 public static CalendarYM fromYM( String pToYM )
  @@ -66,6 +61,11 @@
66 61 return fromStringForm( pToYM, "/" );
67 62 }
68 63
64 + public final String toSQLvalue()
65 + {
66 + return formatSQLvalueYM( this, new StringBuilder() ).toString();
67 + }
68 +
69 69 public static CalendarYM fromSQLvalue( String pToSQLvalue )
70 70 {
71 71 return fromStringForm( pToSQLvalue, "-" );
  @@ -73,40 +73,35 @@
73 73
74 74 private static CalendarYM fromStringForm( String pStringForm, String pSequentialSeperators )
75 75 {
76 - if ( pStringForm == null )
77 - {
78 - return null;
79 - }
80 - String[] parts = SimpleParser.parse( pStringForm, pSequentialSeperators, 2 );
81 - return new CalendarYM( parseInt( parts[0], "Year", pStringForm ), //
82 - parseInt( parts[1], "Month", pStringForm ) );
76 + String[] parts = parseSimple( pStringForm, pSequentialSeperators );
77 + return (parts == null) ? null : //
78 + new CalendarYM( parseYear( pStringForm, parts ), //
79 + parseMonth( pStringForm, parts ) );
83 80 }
84 81
85 82 @Override
86 83 public UtilDateAdaptor toUtilDateAdaptor()
87 84 {
88 - return new UtilDateAdaptor( getYear(), getMonth(), 1 );
85 + return UtilDateAdaptor.currentWall( getYear(), getMonth() );
89 86 }
90 87
91 88 // vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv
92 89
93 - /**
94 - * @param pNewYear != current
95 - */
96 90 @Override
97 - protected CalendarYM LLsetYear( int pNewYear )
91 + protected CalendarYM createTypeFrom( Mutable pMutable )
92 + {
93 + return new CalendarYM( pMutable.getYear(), pMutable.getMonth() );
94 + }
95 +
96 + @Override
97 + protected Mutable createMutable( int pNewYear )
98 98 {
99 - return new CalendarYM( pNewYear, getMonth() );
99 + return new Mutable( pNewYear, getMonth() );
100 100 }
101 101
102 - /**
103 - * @param pNewMonth != current
104 - */
105 102 @Override
106 - protected CalendarYM LLsetMonth( int pNewMonth )
103 + protected Mutable createMutable( int pYear, int pNewMonth )
107 104 {
108 - Mutable zMutable = new Mutable( getYear(), pNewMonth );
109 - zMutable.normalize();
110 - return new CalendarYM( zMutable.getYear(), zMutable.getMonth() );
105 + return new Mutable( pYear, pNewMonth );
111 106 }
112 107 }