Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -2,15 +2,15 @@
2 2
3 3 import org.litesoft.core.typeutils.*;
4 4
5 - public abstract class AbstractTimestampHMS<T extends AbstractTimestampHMS> extends AbstractTimestampHM<T> implements TimestampAccessorHMS
5 + public abstract class AbstractTimestampHMS<T extends AbstractTimestampHMS, M extends AbstractTimestampHMS.Mutable> extends AbstractTimestampHM<T, M> implements TimestampAccessorHMS
6 6 {
7 7 private static final long serialVersionUID = 1L;
8 8
9 9 private final int mSec;
10 10
11 - protected AbstractTimestampHMS( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec )
11 + protected AbstractTimestampHMS( int pYear, int pMonth, int pDay, int pZuluOffsetMins, int pHour, int pMin, int pSec )
12 12 {
13 - super( pYear, pMonth, pDay, pHour, pMin );
13 + super( pYear, pMonth, pDay, pZuluOffsetMins, pHour, pMin );
14 14 mSec = validateSec( pSec );
15 15 }
16 16
  @@ -20,8 +20,57 @@
20 20 return mSec;
21 21 }
22 22
23 + /**
24 + * Return a T with the Sec set to the parameter.
25 + */
26 + public final T sec( int pSec )
27 + {
28 + validateSec( pSec );
29 + return (mSec == pSec) ? us() : LLsetSec( pSec );
30 + }
31 +
32 + /**
33 + * Return T with the parameter pSec added.
34 + */
35 + public final T addSecs( int pSecs )
36 + {
37 + return (pSecs == 0) ? us() : LLsetSec( mSec + pSecs );
38 + }
39 +
40 + /**
41 + * Return T with the parameter pSec subtracted.
42 + */
43 + public final T minusSecs( int pSecs )
44 + {
45 + return (pSecs == 0) ? us() : LLsetSec( mSec - pSecs );
46 + }
47 +
23 48 // vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv
24 49
50 + protected static final int parseSec( String pStringForm, String... pParts )
51 + {
52 + return parseInt( pParts[5], "Sec", pStringForm );
53 + }
54 +
55 + protected static final StringBuilder formatSQLvalueYMDHMS( TimestampAccessorHMS pAccessor, boolean pAddTail, StringBuilder pSB )
56 + {
57 + formatSQLvalueYMDHM( pAccessor, false, pSB ).append( ':' );
58 + formatSec( pAccessor, pSB );
59 + return tailSQLvalue( pAccessor, pAddTail, pSB );
60 + }
61 +
62 + protected static final StringBuilder formatSortableDisplayFormYMDHMS( TimestampAccessorHMS pAccessor, StringBuilder pSB )
63 + {
64 + formatSortableDisplayFormYMDHM( pAccessor, pSB ).append( ':' );
65 + return formatSec( pAccessor, pSB );
66 + }
67 +
68 + protected static final StringBuilder formatSec( TimestampAccessorHMS pAccessor, StringBuilder pSB )
69 + {
70 + pSB.append( Integers.zeroPadIt( 2, pAccessor.getSec() ) );
71 + return pSB;
72 + }
73 +
25 74 protected static final int validateSec( int pSec )
26 75 throws IllegalArgumentException
27 76 {
  @@ -58,15 +107,22 @@
58 107 /**
59 108 * @param pNewMonth != current
60 109 */
61 - abstract protected T LLsetMonth( int pNewMonth, boolean pAdjustForward );
110 + protected final T LLsetSec( int pNewSec )
111 + {
112 + M zMutable = createMutable( getYear(), getMonth(), getDay(), getHour(), getMin(), pNewSec );
113 + zMutable.normalize();
114 + return createTypeFrom( zMutable );
115 + }
116 +
117 + protected abstract M createMutable( int pYear, int pMonth, int pDay, int pHour, int pMin, int pNewSec );
62 118
63 - protected static class Mutable extends AbstractTimestampHM.Mutable
119 + protected static class Mutable extends AbstractTimestampHM.Mutable implements TimestampAccessorHMS
64 120 {
65 121 protected int mSec;
66 122
67 - public Mutable( int pYear, int pMonth, int pDay, boolean pDayConstrained, int pHour, int pMin, int pSec )
123 + public Mutable( int pYear, int pMonth, int pDay, boolean pDayConstrained, int pZuluOffsetMins, int pHour, int pMin, int pSec )
68 124 {
69 - super( pYear, pMonth, pDay, pDayConstrained, pHour, pMin );
125 + super( pYear, pMonth, pDay, pDayConstrained, pZuluOffsetMins, pHour, pMin );
70 126 mSec = pSec;
71 127 }
72 128