Class ServiceDate
- java.lang.Object
-
- org.onebusaway.gtfs.model.calendar.ServiceDate
-
- All Implemented Interfaces:
Serializable,Comparable<ServiceDate>
public class ServiceDate extends Object implements Serializable, Comparable<ServiceDate>
A general representation of a year-month-day tuple not tied to any locale and used by the GTFS entitiesServiceCalendarandServiceCalendarDateto represent service date ranges. A service date is a particular date when a particular GTFS service id is active.- Author:
- bdferris
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ServiceDate()ServiceDate(int year, int month, int day)Construct a new ServiceDate by specifying the numeric year, month, and dayServiceDate(Calendar calendar)ServiceDate(Date date)ServiceDate(ServiceDate o)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ServiceDate o)longdifference(ServiceDate serviceDate)booleanequals(Object obj)CalendargetAsCalendar(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.DategetAsDate()DategetAsDate(TimeZone timeZone)SeegetAsCalendar(TimeZone)for more details.StringgetAsString()intgetDay()intgetMonth()intgetYear()inthashCode()static voidmoveCalendarToServiceDate(Calendar c)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.ServiceDatenext()static ServiceDateparseString(String value)Parse a service date from a string in "YYYYMMDD" format.ServiceDateprevious()ServiceDateshift(int numberOfDays)StringtoString()
-
-
-
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, etcday- - numeric day of month
-
ServiceDate
public ServiceDate(ServiceDate o)
-
ServiceDate
public ServiceDate(Calendar calendar)
-
ServiceDate
public ServiceDate(Date date)
Construct a ServiceDate from the specifiedDateobject, using the defaultTimeZoneobject 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 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
public Date getAsDate(TimeZone timeZone)
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
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
-
compareTo
public int compareTo(ServiceDate o)
- Specified by:
compareToin interfaceComparable<ServiceDate>
-
moveCalendarToServiceDate
public static void moveCalendarToServiceDate(Calendar c)
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
-
-