org.mars_sim.msp.simulation.time
Class MarsClock

java.lang.Object
  extended by org.mars_sim.msp.simulation.time.MarsClock
All Implemented Interfaces:
java.io.Serializable

public class MarsClock
extends java.lang.Object
implements java.io.Serializable

The MarsClock class keeps track of Martian time. This uses Shaun Moss's Mars Calendar, which is described at http://www.virtualmars.net/Time.asp.

See Also:
Serialized Form

Field Summary
static int NORTHERN_HEMISPHERE
           
static int SOLS_IN_ORBIT_LEAPYEAR
           
static int SOLS_IN_ORBIT_NON_LEAPYEAR
           
static int SOUTHERN_HEMISPHERE
           
 
Constructor Summary
MarsClock(int orbit, int month, int sol, double millisol)
          Constructs a MarsClock object with a given time param orbit current orbit param month current month param sol current sol param millisol current millisol
MarsClock(java.lang.String dateString)
          Constructor with date string parameter.
 
Method Summary
 void addTime(double addedMillisols)
          Adds time to the calendar
 java.lang.Object clone()
          Creates a clone of this MarsClock object, with the time set the same.
static double convertMillisolsToSeconds(double millisols)
          Converts millisols to seconds
static double convertSecondsToMillisols(double seconds)
          Converts seconds to millisols
 boolean equals(java.lang.Object object)
          Checks if another object is equal to this one.
 java.lang.String getDateString()
          Gets the current date string.
 double getMillisol()
          Returns the millisol
 int getMonth()
          Returns the month (1 - 24)
 java.lang.String getMonthName()
          Returns the name of the current month.
 int getOrbit()
          Returns the orbit
 java.lang.String getSeason(int hemisphere)
          Returns the current season for the given hemisphere
 int getSolOfMonth()
          Returns the sol of month (1 - 28)
 int getSolOfWeek()
          Returns the sol number of the week (1-7)
 java.lang.String getSolOfWeekName()
          Return the sol name of the week
static int getSolsInMonth(int month, int orbit)
          Returns the number of sols in a month for a given month and orbit.
 int getSolsInWeek()
          Returns the number of sols in the current week
static double getTimeDiff(MarsClock firstTime, MarsClock secondTime)
          Returns the time difference between two Mars clock instances.
 java.lang.String getTimeStamp()
          Returns formatted time stamp string.
 java.lang.String getTimeString()
          Return the current time string.
 int getWeekOfMonth()
          Returns the week of the month (1-4)
 int hashCode()
          Gets the hash code for this object.
static boolean isLeapOrbit(int orbit)
          Returns true if orbit is a leap orbit, false if not.
 java.lang.String toString()
          Displays the string version of the clock.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SOLS_IN_ORBIT_NON_LEAPYEAR

public static final int SOLS_IN_ORBIT_NON_LEAPYEAR
See Also:
Constant Field Values

SOLS_IN_ORBIT_LEAPYEAR

public static final int SOLS_IN_ORBIT_LEAPYEAR
See Also:
Constant Field Values

NORTHERN_HEMISPHERE

public static final int NORTHERN_HEMISPHERE
See Also:
Constant Field Values

SOUTHERN_HEMISPHERE

public static final int SOUTHERN_HEMISPHERE
See Also:
Constant Field Values
Constructor Detail

MarsClock

public MarsClock(java.lang.String dateString)
          throws java.lang.Exception
Constructor with date string parameter.

Parameters:
dateString - format: "orbit-month-sol:millisol"
Throws:
java.lang.Exception - if dateString is invalid.

MarsClock

public MarsClock(int orbit,
                 int month,
                 int sol,
                 double millisol)
Constructs a MarsClock object with a given time param orbit current orbit param month current month param sol current sol param millisol current millisol

Method Detail

convertSecondsToMillisols

public static double convertSecondsToMillisols(double seconds)
Converts seconds to millisols

Parameters:
seconds - decimal number of seconds
Returns:
equivalent number of millisols

convertMillisolsToSeconds

public static double convertMillisolsToSeconds(double millisols)
Converts millisols to seconds

Parameters:
millisols - decimal number of millisols
Returns:
equivalent number of seconds

getTimeDiff

public static double getTimeDiff(MarsClock firstTime,
                                 MarsClock secondTime)
Returns the time difference between two Mars clock instances.

Parameters:
firstTime - first Mars clock instance
secondTime - second Mars clock instance
Returns:
time difference in millisols

getSolsInMonth

public static int getSolsInMonth(int month,
                                 int orbit)
Returns the number of sols in a month for a given month and orbit.

Parameters:
month - the month number
orbit - the orbit number

isLeapOrbit

public static boolean isLeapOrbit(int orbit)
Returns true if orbit is a leap orbit, false if not.

Parameters:
orbit - the orbit number

addTime

public void addTime(double addedMillisols)
Adds time to the calendar

Parameters:
addedMillisols - millisols to be added to the calendar

getTimeStamp

public java.lang.String getTimeStamp()
Returns formatted time stamp string. ex. "13-Adir-05 056.349"

Returns:
formatted timestamp string

getDateString

public java.lang.String getDateString()
Gets the current date string. ex. "13-Adir-05"

Returns:
current date string

getTimeString

public java.lang.String getTimeString()
Return the current time string. ex. "05:056.349"


getMonthName

public java.lang.String getMonthName()
Returns the name of the current month.

Returns:
name of the current month

getOrbit

public int getOrbit()
Returns the orbit

Returns:
the orbit as an integer

getMonth

public int getMonth()
Returns the month (1 - 24)

Returns:
the month as an integer

getSolOfMonth

public int getSolOfMonth()
Returns the sol of month (1 - 28)

Returns:
the sol of month as an integer

getMillisol

public double getMillisol()
Returns the millisol

Returns:
the millisol as a double

getWeekOfMonth

public int getWeekOfMonth()
Returns the week of the month (1-4)

Returns:
the week of the month as an integer

getSolOfWeek

public int getSolOfWeek()
Returns the sol number of the week (1-7)

Returns:
the sol number of the week as an integer

getSolOfWeekName

public java.lang.String getSolOfWeekName()
Return the sol name of the week

Returns:
the sol name of the week as a String

getSolsInWeek

public int getSolsInWeek()
Returns the number of sols in the current week

Returns:
the number of osls in the current week as an integer

getSeason

public java.lang.String getSeason(int hemisphere)
Returns the current season for the given hemisphere

Parameters:
hemisphere - the hemisphere NORTHERN_HEMISPHERE or SOUTHERN_HEMISPHERE valid parameters
Returns:
season as String ("Spring", "Summer", "Autumn" or "Winter")

clone

public java.lang.Object clone()
Creates a clone of this MarsClock object, with the time set the same.

Overrides:
clone in class java.lang.Object
Returns:
clone of this MarsClock object

toString

public java.lang.String toString()
Displays the string version of the clock.

Overrides:
toString in class java.lang.Object
Returns:
time stamp string.

equals

public boolean equals(java.lang.Object object)
Checks if another object is equal to this one.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Gets the hash code for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
hash code.