Class ServiceDate

    • Constructor Detail

      • ServiceDate

        public ServiceDate​(int year,
                           int month,
                           int day)
        Construct a new ServiceDate by specifying the numeric year, month, and day
        Parameters:
        year - - numeric year (ex. 2010)
        month - - numeric month of the year, where Jan = 1, Feb = 2, etc
        day - - numeric day of month
      • ServiceDate

        public ServiceDate​(Calendar calendar)
      • ServiceDate

        public ServiceDate​(Date date)
        Construct a ServiceDate from the specified Date object, using the default TimeZone object for the current VM to localize the date
        Parameters:
        date -
      • ServiceDate

        public ServiceDate()
    • Method Detail

      • parseString

        public static ServiceDate parseString​(String value)
                                       throws ParseException
        Parse a service date from a string in "YYYYMMDD" format.
        Parameters:
        value - a string of the form "YYYYMMDD"
        Returns:
        a new ServiceDate object
        Throws:
        ParseException - on parse error
      • getYear

        public int getYear()
      • getMonth

        public int getMonth()
      • getDay

        public int getDay()
      • getAsDate

        public Date getAsDate()
        Returns:
        calls getAsDate(TimeZone) with the default timezone for this VM. Be careful, this may return a time of 00:00:00 or 01:00:00 or 23:00:00 of the day before depending on EST or EDT
      • getAsCalendar

        public Calendar getAsCalendar​(TimeZone timeZone)
        Constructs a Calendar object such that the Calendar will be at "midnight" (12:00am) at the start of the day specified by this service date and the target timezone. Note that we take the GTFS convention of calculating midnight by setting the target date to noon (12:00pm) for the service date and timezone specified and then subtracting twelve hours. Normally that would be equivalent to midnight, except on Daylight Saving Time days, in which case it can be an hour ahead or behind. This behavior ensures correct calculation of StopTime arrival and departure time when the second offset is added to the localized service date.
        Parameters:
        timeZone - the target timezone to localize the service date to
        Returns:
        a localized date at "midnight" at the start of this service date in the specified timezone
      • getAsDate

        public Date getAsDate​(TimeZone timeZone)
        See getAsCalendar(TimeZone) for more details.
        Parameters:
        timeZone - the target timezone to localize the service date to
        Returns:
        a localized date at "midnight" at the start of this service date in the specified timezone
      • getAsString

        public String getAsString()
        Returns:
        a string in "YYYYMMDD" format
      • next

        public ServiceDate next()
        Returns:
        the service date following the current service date
      • previous

        public ServiceDate previous()
        Returns:
        the service date preceding the current service date
      • shift

        public ServiceDate shift​(int numberOfDays)
        Parameters:
        numberOfDays -
        Returns:
        the service date following the current service date by the specified number of days, or preceding if a negative number of days is specified
      • difference

        public long difference​(ServiceDate serviceDate)
        Parameters:
        serviceDate -
        Returns:
        the number of days between this service date and the specified argument service date
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • moveCalendarToServiceDate

        public static void moveCalendarToServiceDate​(Calendar c)
        Adjust the supplied Calendar object such that the calendar will be at "midnight" (12:00am) at the start of the day specified by the current calendar date and locale. Note that we take the GTFS convention of calculating midnight by setting the target date to noon (12:00pm) for the service date and timezone specified and then subtracting twelve hours. Normally that would be equivalent to midnight, except on Daylight Saving Time days, in which case it can be an hour ahead or behind. This behavior ensures correct calculation of StopTime arrival and departure time when the second offset is added to the localized service date.
        Parameters:
        c - the target calendar, already to some time on the target date