diff options
| author | Benjamin Culkin <scorpress@gmail.com> | 2024-05-20 17:58:16 -0400 |
|---|---|---|
| committer | Benjamin Culkin <scorpress@gmail.com> | 2024-05-20 17:58:16 -0400 |
| commit | 40a9d99496e098562f090fb7ffce9e749011b131 (patch) | |
| tree | 437df24d65470582e943e494a52db8ed65a881ae /projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSDate.java | |
| parent | ff072dfe782f6f22123cd4ba050828d35c0d0fbd (diff) | |
Formatting pass
Diffstat (limited to 'projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSDate.java')
| -rw-r--r-- | projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSDate.java | 319 |
1 files changed, 149 insertions, 170 deletions
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSDate.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSDate.java index d5b6f61..a2121fd 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSDate.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSDate.java @@ -23,17 +23,16 @@ import java.util.GregorianCalendar; import java.util.TimeZone; /** -* A pure java implementation of NSDate that extends -* java.util.Date for greater java compatibility. -* -* @author michael@mpowers.net -* @author $Author: cgruber $ -* @version $Revision: 892 $ -*/ -public class NSDate extends Date -{ + * A pure java implementation of NSDate that extends java.util.Date for greater + * java compatibility. + * + * @author michael@mpowers.net + * @author $Author: cgruber $ + * @version $Revision: 892 $ + */ +public class NSDate extends Date { // NSComparisonResult compatibility - + public static final int NSOrderedAscending = -1; public static final int NSOrderedSame = 0; public static final int NSOrderedDescending = 1; @@ -41,158 +40,142 @@ public class NSDate extends Date // public static final double TimeIntervalSince1970; // public static final NSDate DateFor1970; - /** - * Default constructor represents the current date. - */ - public NSDate () - { - super(); - } - - /** - * Represents the specified number of seconds from the current date. - */ - public NSDate (double seconds) - { - super( (long) new NSDate().getTime() + - timeIntervalToMilliseconds(seconds) ); - } - - /** - * Represents the specified number of seconds from the specified date. - */ - public NSDate (double seconds, Date sinceDate) - { - super( (long) sinceDate.getTime() + - timeIntervalToMilliseconds(seconds) ); - } - - /** - * Returns the interval between this date and 1 January 2001 GMT. - */ - public double timeIntervalSinceReferenceDate () - { - GregorianCalendar referenceDate = - new GregorianCalendar( TimeZone.getTimeZone( "GMT" ) ); - referenceDate.set( 2001, 0, 0, 0, 0, 0 ); - return timeIntervalSinceDate( referenceDate.getTime() ); - } - - /** - * Returns the interval between this date and the specified date - * in seconds. - */ - public double timeIntervalSinceDate (Date aDate) - { - return millisecondsToTimeInterval( - this.getTime() - aDate.getTime() ); - } - - /** - * Returns the interval between this date and the current date - * in seconds. - */ - public double timeIntervalSinceNow () - { - return timeIntervalSinceDate( new NSDate() ); - } - - /** - * Compares this date to the specified date and returns the - * earlier date. Unspecified which is returned if both are equal. - */ - public NSDate earlierDate (NSDate aDate) - { - if ( aDate == null ) return this; - if ( after( aDate ) ) return aDate; - return this; - } - - /** - * Compares this date to the specified date and returns the - * later date. Unspecified which is returned if both are equal. - */ - public NSDate laterDate (NSDate aDate) - { - if ( aDate == null ) return this; - if ( before( aDate ) ) return aDate; - return this; - } - - /** - * Returns a negative value if the specified date is later than - * this date, a positive value if the specified date is earlier - * than this date, or zero if the dates are equal. The return - * values are compatible with type NSComparisonResult. - */ - public int compare (Date aDate) - { - if ( before( aDate ) ) return NSOrderedAscending; - if ( after( aDate ) ) return NSOrderedDescending; - return NSOrderedSame; - } - - /** - * Returns whether the this date is equal to the specified date, - * per the result of equals(). - */ - public boolean isEqualToDate (Date aDate) - { - return equals( aDate ); - } - - /** - * Returns a date that differs from this date by the specified - * number of seconds. - */ - public NSDate dateByAddingTimeInterval (double seconds) - { - return new NSDate( seconds, this ); - } - - /** - * Returns the number of seconds between now and the reference date. - */ - public static double currentTimeIntervalSinceReferenceDate () - { - return new NSDate().timeIntervalSinceReferenceDate(); - } - - /** - * Converts seconds to milliseconds. Included for compatibility. - */ - public static long timeIntervalToMilliseconds (double seconds) - { - return (long) seconds*1000; - } - - /** - * Converts milliseconds to seconds. Included for compatibility. - */ - public static double millisecondsToTimeInterval (long millis) - { - return millis/1000.0; - } - - /** - * Returns a date that is greater than all representable dates. - */ - public static NSDate distantFuture () - { - NSDate result = new NSDate(); - result.setTime( Long.MAX_VALUE ); - return result; - } - - /** - * Returns a date that is less than all representable dates. - */ - public static NSDate distantPast () - { - NSDate result = new NSDate(); - result.setTime( Long.MIN_VALUE ); - return result; - } + /** + * Default constructor represents the current date. + */ + public NSDate() { + super(); + } + + /** + * Represents the specified number of seconds from the current date. + */ + public NSDate(double seconds) { + super((long) new NSDate().getTime() + timeIntervalToMilliseconds(seconds)); + } + + /** + * Represents the specified number of seconds from the specified date. + */ + public NSDate(double seconds, Date sinceDate) { + super((long) sinceDate.getTime() + timeIntervalToMilliseconds(seconds)); + } + + /** + * Returns the interval between this date and 1 January 2001 GMT. + */ + public double timeIntervalSinceReferenceDate() { + GregorianCalendar referenceDate = new GregorianCalendar(TimeZone.getTimeZone("GMT")); + referenceDate.set(2001, 0, 0, 0, 0, 0); + return timeIntervalSinceDate(referenceDate.getTime()); + } + + /** + * Returns the interval between this date and the specified date in seconds. + */ + public double timeIntervalSinceDate(Date aDate) { + return millisecondsToTimeInterval(this.getTime() - aDate.getTime()); + } + + /** + * Returns the interval between this date and the current date in seconds. + */ + public double timeIntervalSinceNow() { + return timeIntervalSinceDate(new NSDate()); + } + + /** + * Compares this date to the specified date and returns the earlier date. + * Unspecified which is returned if both are equal. + */ + public NSDate earlierDate(NSDate aDate) { + if (aDate == null) + return this; + if (after(aDate)) + return aDate; + return this; + } + + /** + * Compares this date to the specified date and returns the later date. + * Unspecified which is returned if both are equal. + */ + public NSDate laterDate(NSDate aDate) { + if (aDate == null) + return this; + if (before(aDate)) + return aDate; + return this; + } + + /** + * Returns a negative value if the specified date is later than this date, a + * positive value if the specified date is earlier than this date, or zero if + * the dates are equal. The return values are compatible with type + * NSComparisonResult. + */ + public int compare(Date aDate) { + if (before(aDate)) + return NSOrderedAscending; + if (after(aDate)) + return NSOrderedDescending; + return NSOrderedSame; + } + + /** + * Returns whether the this date is equal to the specified date, per the result + * of equals(). + */ + public boolean isEqualToDate(Date aDate) { + return equals(aDate); + } + + /** + * Returns a date that differs from this date by the specified number of + * seconds. + */ + public NSDate dateByAddingTimeInterval(double seconds) { + return new NSDate(seconds, this); + } + + /** + * Returns the number of seconds between now and the reference date. + */ + public static double currentTimeIntervalSinceReferenceDate() { + return new NSDate().timeIntervalSinceReferenceDate(); + } + + /** + * Converts seconds to milliseconds. Included for compatibility. + */ + public static long timeIntervalToMilliseconds(double seconds) { + return (long) seconds * 1000; + } + + /** + * Converts milliseconds to seconds. Included for compatibility. + */ + public static double millisecondsToTimeInterval(long millis) { + return millis / 1000.0; + } + + /** + * Returns a date that is greater than all representable dates. + */ + public static NSDate distantFuture() { + NSDate result = new NSDate(); + result.setTime(Long.MAX_VALUE); + return result; + } + + /** + * Returns a date that is less than all representable dates. + */ + public static NSDate distantPast() { + NSDate result = new NSDate(); + result.setTime(Long.MIN_VALUE); + return result; + } // inherited from java.util.Date // public java.lang.String toString (); @@ -202,16 +185,12 @@ public class NSDate extends Date } /* - * $Log$ - * Revision 1.1 2006/02/16 12:47:16 cgruber - * Check in all sources in eclipse-friendly maven-enabled packages. + * $Log$ Revision 1.1 2006/02/16 12:47:16 cgruber Check in all sources in + * eclipse-friendly maven-enabled packages. * - * Revision 1.1.1.1 2000/12/21 15:47:28 mpowers - * Contributing wotonomy. + * Revision 1.1.1.1 2000/12/21 15:47:28 mpowers Contributing wotonomy. * - * Revision 1.3 2000/12/20 16:25:38 michael - * Added log to all files. + * Revision 1.3 2000/12/20 16:25:38 michael Added log to all files. * * */ - |
