Class ServiceDate
java.lang.Object
org.onebusaway.gtfs.model.calendar.ServiceDate
- All Implemented Interfaces:
Serializable,Comparable<ServiceDate>
A general representation of a year-month-day tuple not tied to any locale and
used by the GTFS entities
ServiceCalendar and
ServiceCalendarDate to represent service date ranges. A service date
is a particular date when a particular GTFS service id is active.- Author:
- bdferris
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionServiceDate(int year, int month, int day) Construct a new ServiceDate by specifying the numeric year, month, and dayServiceDate(Calendar calendar) ServiceDate(Date date) -
Method Summary
Modifier and TypeMethodDescriptionintlongdifference(ServiceDate serviceDate) booleangetAsCalendar(TimeZone timeZone) Constructs aCalendarobject 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.SeegetAsCalendar(TimeZone)for more details.intgetDay()intgetMonth()intgetYear()inthashCode()static voidAdjust the suppliedCalendarobject such that the calendar will be at "midnight" (12:00am) at the start of the day specified by the current calendar date and locale.next()static ServiceDateparseString(String value) Parse a service date from a string in "YYYYMMDD" format.previous()shift(int numberOfDays) toString()
-
Constructor Details
-
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, etcday- - numeric day of month
-
ServiceDate
-
ServiceDate
-
ServiceDate
Construct a ServiceDate from the specifiedDateobject, using the defaultTimeZoneobject for the current VM to localize the date- Parameters:
date-
-
ServiceDate
public ServiceDate()
-
-
Method Details
-
parseString
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
- 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
Constructs aCalendarobject 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 ofStopTimearrival 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
SeegetAsCalendar(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
- Returns:
- a string in "YYYYMMDD" format
-
next
- Returns:
- the service date following the current service date
-
previous
- Returns:
- the service date preceding the current service date
-
shift
- 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
- Parameters:
serviceDate-- Returns:
- the number of days between this service date and the specified argument service date
-
compareTo
- Specified by:
compareToin interfaceComparable<ServiceDate>
-
toString
-
hashCode
public int hashCode() -
equals
-
moveCalendarToServiceDate
Adjust the suppliedCalendarobject 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 ofStopTimearrival 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
-