Java Doc for Period.java in  » Development » Joda-Time » org » joda » time » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » Joda Time » org.joda.time 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.joda.time.base.BasePeriod
   org.joda.time.Period

Period
final public class Period extends BasePeriod implements ReadablePeriod,Serializable(Code)
An immutable time period specifying a set of duration field values.

A time period is divided into a number of fields, such as hours and seconds. Which fields are supported is defined by the PeriodType class. The default is the standard period type, which supports years, months, weeks, days, hours, minutes, seconds and millis.

When this time period is added to an instant, the effect is of adding each field in turn. As a result, this takes into account daylight savings time. Adding a time period of 1 day to the day before daylight savings starts will only add 23 hours rather than 24 to ensure that the time remains the same. If this is not the behaviour you want, then see Duration .

The definition of a period also affects the equals method. A period of 1 day is not equal to a period of 24 hours, nor 1 hour equal to 60 minutes. This is because periods represent an abstracted definition of a time period (eg. a day may not actually be 24 hours, it might be 23 or 25 at daylight savings boundary). To compare the actual duration of two periods, convert both to durations using toDuration, an operation that emphasises that the result may differ according to the date you choose.

Period is thread-safe and immutable, provided that the PeriodType is as well. All standard PeriodType classes supplied are thread-safe and immutable.
author:
   Brian S O'Neill
author:
   Stephen Colebourne
since:
   1.0
See Also:   MutablePeriod



Field Summary
final public static  PeriodZERO
     A period of zero length and standard period type.

Constructor Summary
public  Period()
     Creates a new empty period with the standard set of fields.
public  Period(int hours, int minutes, int seconds, int millis)
     Create a period from a set of field values using the standard set of fields.
public  Period(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis)
     Create a period from a set of field values using the standard set of fields.
public  Period(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis, PeriodType type)
     Create a period from a set of field values.
public  Period(long duration)
     Creates a period from the given millisecond duration using the standard set of fields.
public  Period(long duration, PeriodType type)
     Creates a period from the given millisecond duration.
public  Period(long duration, Chronology chronology)
     Creates a period from the given millisecond duration using the standard set of fields.
public  Period(long duration, PeriodType type, Chronology chronology)
     Creates a period from the given millisecond duration.
public  Period(long startInstant, long endInstant)
     Creates a period from the given interval endpoints using the standard set of fields.
public  Period(long startInstant, long endInstant, PeriodType type)
     Creates a period from the given interval endpoints.
public  Period(long startInstant, long endInstant, Chronology chrono)
     Creates a period from the given interval endpoints using the standard set of fields.
public  Period(long startInstant, long endInstant, PeriodType type, Chronology chrono)
     Creates a period from the given interval endpoints.
public  Period(ReadableInstant startInstant, ReadableInstant endInstant)
     Creates a period from the given interval endpoints using the standard set of fields.
public  Period(ReadableInstant startInstant, ReadableInstant endInstant, PeriodType type)
     Creates a period from the given interval endpoints.
public  Period(ReadablePartial start, ReadablePartial end)
     Creates a period from two partially specified times.
public  Period(ReadablePartial start, ReadablePartial end, PeriodType type)
     Creates a period from two partially specified times.
public  Period(ReadableInstant startInstant, ReadableDuration duration)
     Creates a period from the given start point and the duration.
public  Period(ReadableInstant startInstant, ReadableDuration duration, PeriodType type)
     Creates a period from the given start point and the duration.
public  Period(ReadableDuration duration, ReadableInstant endInstant)
     Creates a period from the given duration and end point.
public  Period(ReadableDuration duration, ReadableInstant endInstant, PeriodType type)
     Creates a period from the given duration and end point.
public  Period(Object period)
     Creates a period by converting or copying from another object.
public  Period(Object period, PeriodType type)
     Creates a period by converting or copying from another object.
public  Period(Object period, Chronology chrono)
     Creates a period by converting or copying from another object.
public  Period(Object period, PeriodType type, Chronology chrono)
     Creates a period by converting or copying from another object.

Method Summary
public static  Perioddays(int days)
     Create a period with a specified number of days.
public static  PeriodfieldDifference(ReadablePartial start, ReadablePartial end)
     Creates a period from two partially specified times, calculating by field difference.

The two partials must contain the same fields, thus you can specify two LocalDate objects, or two LocalTime objects, but not one of each.

public  intgetDays()
     Gets the days field part of the period.
public  intgetHours()
     Gets the hours field part of the period.
public  intgetMillis()
     Gets the millis field part of the period.
public  intgetMinutes()
     Gets the minutes field part of the period.
public  intgetMonths()
     Gets the months field part of the period.
public  intgetSeconds()
     Gets the seconds field part of the period.
public  intgetWeeks()
     Gets the weeks field part of the period.
public  intgetYears()
     Gets the years field part of the period.
public static  Periodhours(int hours)
     Create a period with a specified number of hours.
public static  Periodmillis(int millis)
     Create a period with a specified number of millis.
public  Periodminus(ReadablePeriod period)
     Returns a new period with the specified period subtracted.

Each field of the period is subtracted separately.

public  PeriodminusDays(int days)
     Returns a new period minus the specified number of days taken away.
public  PeriodminusHours(int hours)
     Returns a new period minus the specified number of hours taken away.
public  PeriodminusMillis(int millis)
     Returns a new period minus the specified number of millis taken away.
public  PeriodminusMinutes(int minutes)
     Returns a new period minus the specified number of minutes taken away.
public  PeriodminusMonths(int months)
     Returns a new period minus the specified number of months taken away.
public  PeriodminusSeconds(int seconds)
     Returns a new period minus the specified number of seconds taken away.
public  PeriodminusWeeks(int weeks)
     Returns a new period minus the specified number of weeks taken away.
public  PeriodminusYears(int years)
     Returns a new period with the specified number of years taken away.
public static  Periodminutes(int minutes)
     Create a period with a specified number of minutes.
public static  Periodmonths(int months)
     Create a period with a specified number of months.
public  PeriodnormalizedStandard()
     Normalizes this period using standard rules, assuming a 12 month year, 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to normalize a period. However to achieve this it makes the assumption that all years are 12 months, all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds.

public  PeriodnormalizedStandard(PeriodType type)
     Normalizes this period using standard rules, assuming a 12 month year, 7 day week, 24 hour day, 60 minute hour and 60 second minute, providing control over how the result is split into fields.

This method allows you to normalize a period. However to achieve this it makes the assumption that all years are 12 months, all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds.

public  Periodplus(ReadablePeriod period)
     Returns a new period with the specified period added.

Each field of the period is added separately.

public  PeriodplusDays(int days)
     Returns a new period plus the specified number of days added.
public  PeriodplusHours(int hours)
     Returns a new period plus the specified number of hours added.
public  PeriodplusMillis(int millis)
     Returns a new period plus the specified number of millis added.
public  PeriodplusMinutes(int minutes)
     Returns a new period plus the specified number of minutes added.
public  PeriodplusMonths(int months)
     Returns a new period plus the specified number of months added.
public  PeriodplusSeconds(int seconds)
     Returns a new period plus the specified number of seconds added.
public  PeriodplusWeeks(int weeks)
     Returns a new period plus the specified number of weeks added.
public  PeriodplusYears(int years)
     Returns a new period with the specified number of years added.
public static  Periodseconds(int seconds)
     Create a period with a specified number of seconds.
public  PeriodtoPeriod()
     Get this period as an immutable Period object by returning this.
public  DaystoStandardDays()
     Converts this period to a period in days assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds.

public  DurationtoStandardDuration()
     Converts this period to a duration assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert from a period to a duration. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds.

public  HourstoStandardHours()
     Converts this period to a period in hours assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds.

public  MinutestoStandardMinutes()
     Converts this period to a period in minutes assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds.

public  SecondstoStandardSeconds()
     Converts this period to a period in seconds assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds.

public  WeekstoStandardWeeks()
     Converts this period to a period in weeks assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds.

public static  Periodweeks(int weeks)
     Create a period with a specified number of weeks.
public  PeriodwithDays(int days)
     Returns a new period with the specified number of days.
public  PeriodwithField(DurationFieldType field, int value)
     Creates a new Period instance with the specified field set to a new value.
public  PeriodwithFieldAdded(DurationFieldType field, int value)
     Creates a new Period instance with the valueToAdd added to the specified field.
public  PeriodwithFields(ReadablePeriod period)
     Creates a new Period instance with the fields from the specified period copied on top of those from this period.
public  PeriodwithHours(int hours)
     Returns a new period with the specified number of hours.
public  PeriodwithMillis(int millis)
     Returns a new period with the specified number of millis.
public  PeriodwithMinutes(int minutes)
     Returns a new period with the specified number of minutes.
public  PeriodwithMonths(int months)
     Returns a new period with the specified number of months.
public  PeriodwithPeriodType(PeriodType type)
     Creates a new Period instance with the same field values but different PeriodType.
public  PeriodwithSeconds(int seconds)
     Returns a new period with the specified number of seconds.
public  PeriodwithWeeks(int weeks)
     Returns a new period with the specified number of weeks.
public  PeriodwithYears(int years)
     Returns a new period with the specified number of years.
public static  Periodyears(int years)
     Create a period with a specified number of years.

Field Detail
ZERO
final public static Period ZERO(Code)
A period of zero length and standard period type.
since:
   1.4




Constructor Detail
Period
public Period()(Code)
Creates a new empty period with the standard set of fields.

One way to initialise a period is as follows:

 Period = new Period().withYears(6).withMonths(3).withSeconds(23);
 
Bear in mind that this creates four period instances in total, three of which are immediately discarded. The alterative is more efficient, but less readable:
 Period = new Period(6, 3, 0, 0, 0, 0, 23, 0);
 
The following is also slightly less wasteful:
 Period = Period.years(6).withMonths(3).withSeconds(23);
 



Period
public Period(int hours, int minutes, int seconds, int millis)(Code)
Create a period from a set of field values using the standard set of fields. Note that the parameters specify the time fields hours, minutes, seconds and millis, not the date fields.
Parameters:
  hours - amount of hours in this period
Parameters:
  minutes - amount of minutes in this period
Parameters:
  seconds - amount of seconds in this period
Parameters:
  millis - amount of milliseconds in this period



Period
public Period(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis)(Code)
Create a period from a set of field values using the standard set of fields.
Parameters:
  years - amount of years in this period
Parameters:
  months - amount of months in this period
Parameters:
  weeks - amount of weeks in this period
Parameters:
  days - amount of days in this period
Parameters:
  hours - amount of hours in this period
Parameters:
  minutes - amount of minutes in this period
Parameters:
  seconds - amount of seconds in this period
Parameters:
  millis - amount of milliseconds in this period



Period
public Period(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis, PeriodType type)(Code)
Create a period from a set of field values.

There is usually little need to use this constructor. The period type is used primarily to define how to split an interval into a period. As this constructor already is split, the period type does no real work.
Parameters:
  years - amount of years in this period, which must be zero if unsupported
Parameters:
  months - amount of months in this period, which must be zero if unsupported
Parameters:
  weeks - amount of weeks in this period, which must be zero if unsupported
Parameters:
  days - amount of days in this period, which must be zero if unsupported
Parameters:
  hours - amount of hours in this period, which must be zero if unsupported
Parameters:
  minutes - amount of minutes in this period, which must be zero if unsupported
Parameters:
  seconds - amount of seconds in this period, which must be zero if unsupported
Parameters:
  millis - amount of milliseconds in this period, which must be zero if unsupported
Parameters:
  type - which set of fields this period supports, null means AllType
throws:
  IllegalArgumentException - if an unsupported field's value is non-zero




Period
public Period(long duration)(Code)
Creates a period from the given millisecond duration using the standard set of fields.

Only precise fields in the period type will be used. For the standard period type this is the time fields only. Thus the year, month, week and day fields will not be populated.

If the duration is small, less than one day, then this method will perform as you might expect and split the fields evenly.

If the duration is larger than one day then all the remaining duration will be stored in the largest available precise field, hours in this case.

For example, a duration equal to (365 + 60 + 5) days will be converted to ((365 + 60 + 5) * 24) hours by this constructor.

For more control over the conversion process, you have two options:

  • convert the duration to an Interval , and from there obtain the period
  • specify a period type that contains precise definitions of the day and larger fields, such as UTC

Parameters:
  duration - the duration, in milliseconds



Period
public Period(long duration, PeriodType type)(Code)
Creates a period from the given millisecond duration.

Only precise fields in the period type will be used. Imprecise fields will not be populated.

If the duration is small then this method will perform as you might expect and split the fields evenly.

If the duration is large then all the remaining duration will be stored in the largest available precise field. For details as to which fields are precise, review the period type javadoc.
Parameters:
  duration - the duration, in milliseconds
Parameters:
  type - which set of fields this period supports, null means standard




Period
public Period(long duration, Chronology chronology)(Code)
Creates a period from the given millisecond duration using the standard set of fields.

Only precise fields in the period type will be used. Imprecise fields will not be populated.

If the duration is small then this method will perform as you might expect and split the fields evenly.

If the duration is large then all the remaining duration will be stored in the largest available precise field. For details as to which fields are precise, review the period type javadoc.
Parameters:
  duration - the duration, in milliseconds
Parameters:
  chronology - the chronology to use to split the duration, null means ISO default




Period
public Period(long duration, PeriodType type, Chronology chronology)(Code)
Creates a period from the given millisecond duration.

Only precise fields in the period type will be used. Imprecise fields will not be populated.

If the duration is small then this method will perform as you might expect and split the fields evenly.

If the duration is large then all the remaining duration will be stored in the largest available precise field. For details as to which fields are precise, review the period type javadoc.
Parameters:
  duration - the duration, in milliseconds
Parameters:
  type - which set of fields this period supports, null means standard
Parameters:
  chronology - the chronology to use to split the duration, null means ISO default




Period
public Period(long startInstant, long endInstant)(Code)
Creates a period from the given interval endpoints using the standard set of fields.
Parameters:
  startInstant - interval start, in milliseconds
Parameters:
  endInstant - interval end, in milliseconds



Period
public Period(long startInstant, long endInstant, PeriodType type)(Code)
Creates a period from the given interval endpoints.
Parameters:
  startInstant - interval start, in milliseconds
Parameters:
  endInstant - interval end, in milliseconds
Parameters:
  type - which set of fields this period supports, null means standard



Period
public Period(long startInstant, long endInstant, Chronology chrono)(Code)
Creates a period from the given interval endpoints using the standard set of fields.
Parameters:
  startInstant - interval start, in milliseconds
Parameters:
  endInstant - interval end, in milliseconds
Parameters:
  chrono - the chronology to use, null means ISO in default zone



Period
public Period(long startInstant, long endInstant, PeriodType type, Chronology chrono)(Code)
Creates a period from the given interval endpoints.
Parameters:
  startInstant - interval start, in milliseconds
Parameters:
  endInstant - interval end, in milliseconds
Parameters:
  type - which set of fields this period supports, null means standard
Parameters:
  chrono - the chronology to use, null means ISO in default zone



Period
public Period(ReadableInstant startInstant, ReadableInstant endInstant)(Code)
Creates a period from the given interval endpoints using the standard set of fields.
Parameters:
  startInstant - interval start, null means now
Parameters:
  endInstant - interval end, null means now



Period
public Period(ReadableInstant startInstant, ReadableInstant endInstant, PeriodType type)(Code)
Creates a period from the given interval endpoints.
Parameters:
  startInstant - interval start, null means now
Parameters:
  endInstant - interval end, null means now
Parameters:
  type - which set of fields this period supports, null means standard



Period
public Period(ReadablePartial start, ReadablePartial end)(Code)
Creates a period from two partially specified times.

The two partials must contain the same fields, thus you can specify two LocalDate objects, or two LocalTime objects, but not one of each. As these are Partial objects, time zones have no effect on the result.

The two partials must also both be contiguous - see DateTimeUtils.isContiguous(ReadablePartial) for a definition. Both LocalDate and LocalTime are contiguous.

An alternative way of constructing a Period from two Partials is Period.fieldDifference(ReadablePartial,ReadablePartial) . That method handles all kinds of partials.
Parameters:
  start - the start of the period, must not be null
Parameters:
  end - the end of the period, must not be null
throws:
  IllegalArgumentException - if the partials are null or invalid
since:
   1.1




Period
public Period(ReadablePartial start, ReadablePartial end, PeriodType type)(Code)
Creates a period from two partially specified times.

The two partials must contain the same fields, thus you can specify two LocalDate objects, or two LocalTime objects, but not one of each. As these are Partial objects, time zones have no effect on the result.

The two partials must also both be contiguous - see DateTimeUtils.isContiguous(ReadablePartial) for a definition. Both LocalDate and LocalTime are contiguous.

An alternative way of constructing a Period from two Partials is Period.fieldDifference(ReadablePartial,ReadablePartial) . That method handles all kinds of partials.
Parameters:
  start - the start of the period, must not be null
Parameters:
  end - the end of the period, must not be null
Parameters:
  type - which set of fields this period supports, null means standard
throws:
  IllegalArgumentException - if the partials are null or invalid
since:
   1.1




Period
public Period(ReadableInstant startInstant, ReadableDuration duration)(Code)
Creates a period from the given start point and the duration.
Parameters:
  startInstant - the interval start, null means now
Parameters:
  duration - the duration of the interval, null means zero-length



Period
public Period(ReadableInstant startInstant, ReadableDuration duration, PeriodType type)(Code)
Creates a period from the given start point and the duration.
Parameters:
  startInstant - the interval start, null means now
Parameters:
  duration - the duration of the interval, null means zero-length
Parameters:
  type - which set of fields this period supports, null means standard



Period
public Period(ReadableDuration duration, ReadableInstant endInstant)(Code)
Creates a period from the given duration and end point.
Parameters:
  duration - the duration of the interval, null means zero-length
Parameters:
  endInstant - the interval end, null means now



Period
public Period(ReadableDuration duration, ReadableInstant endInstant, PeriodType type)(Code)
Creates a period from the given duration and end point.
Parameters:
  duration - the duration of the interval, null means zero-length
Parameters:
  endInstant - the interval end, null means now
Parameters:
  type - which set of fields this period supports, null means standard



Period
public Period(Object period)(Code)
Creates a period by converting or copying from another object.

The recognised object types are defined in org.joda.time.convert.ConverterManager ConverterManager and include ReadablePeriod, ReadableInterval and String. The String formats are described by ISOPeriodFormat.standard .
Parameters:
  period - period to convert
throws:
  IllegalArgumentException - if period is invalid
throws:
  UnsupportedOperationException - if an unsupported field's value is non-zero




Period
public Period(Object period, PeriodType type)(Code)
Creates a period by converting or copying from another object.

The recognised object types are defined in org.joda.time.convert.ConverterManager ConverterManager and include ReadablePeriod, ReadableInterval and String. The String formats are described by ISOPeriodFormat.standard .
Parameters:
  period - period to convert
Parameters:
  type - which set of fields this period supports, null means use converter
throws:
  IllegalArgumentException - if period is invalid
throws:
  UnsupportedOperationException - if an unsupported field's value is non-zero




Period
public Period(Object period, Chronology chrono)(Code)
Creates a period by converting or copying from another object.

The recognised object types are defined in org.joda.time.convert.ConverterManager ConverterManager and include ReadablePeriod, ReadableInterval and String. The String formats are described by ISOPeriodFormat.standard .
Parameters:
  period - period to convert
Parameters:
  chrono - the chronology to use, null means ISO in default zone
throws:
  IllegalArgumentException - if period is invalid
throws:
  UnsupportedOperationException - if an unsupported field's value is non-zero




Period
public Period(Object period, PeriodType type, Chronology chrono)(Code)
Creates a period by converting or copying from another object.

The recognised object types are defined in org.joda.time.convert.ConverterManager ConverterManager and include ReadablePeriod, ReadableInterval and String. The String formats are described by ISOPeriodFormat.standard .
Parameters:
  period - period to convert
Parameters:
  type - which set of fields this period supports, null means use converter
Parameters:
  chrono - the chronology to use, null means ISO in default zone
throws:
  IllegalArgumentException - if period is invalid
throws:
  UnsupportedOperationException - if an unsupported field's value is non-zero





Method Detail
days
public static Period days(int days)(Code)
Create a period with a specified number of days.

The standard period type is used, thus you can add other fields such as months or weeks using the withXxx() methods. For example, Period.days(2).withHours(6);

If you want a day-based period that cannot have other fields added, then you should consider using Days .
Parameters:
  days - the amount of days in this period the period




fieldDifference
public static Period fieldDifference(ReadablePartial start, ReadablePartial end)(Code)
Creates a period from two partially specified times, calculating by field difference.

The two partials must contain the same fields, thus you can specify two LocalDate objects, or two LocalTime objects, but not one of each. Also, the partial may not contain overlapping fields, such as dayOfWeek and dayOfMonth.

Calculation by field difference works by extracting the difference one field at a time and not wrapping into other fields. Thus 2005-06-09/2007-04-12 will yield P1Y-2M3D.

For example, you have an event that always runs from the 27th of each month to the 2nd of the next month. If you calculate this period using a standard constructor, then you will get between P3D and P6D depending on the month. If you use this method, then you will get P1M-25D. This field-difference based period can be successfully applied to each month of the year to obtain the correct end date for a given start date.
Parameters:
  start - the start of the period, must not be null
Parameters:
  end - the end of the period, must not be null
throws:
  IllegalArgumentException - if the partials are null or invalid
since:
   1.1




getDays
public int getDays()(Code)
Gets the days field part of the period. the number of days in the period, zero if unsupported



getHours
public int getHours()(Code)
Gets the hours field part of the period. the number of hours in the period, zero if unsupported



getMillis
public int getMillis()(Code)
Gets the millis field part of the period. the number of millis in the period, zero if unsupported



getMinutes
public int getMinutes()(Code)
Gets the minutes field part of the period. the number of minutes in the period, zero if unsupported



getMonths
public int getMonths()(Code)
Gets the months field part of the period. the number of months in the period, zero if unsupported



getSeconds
public int getSeconds()(Code)
Gets the seconds field part of the period. the number of seconds in the period, zero if unsupported



getWeeks
public int getWeeks()(Code)
Gets the weeks field part of the period. the number of weeks in the period, zero if unsupported



getYears
public int getYears()(Code)
Gets the years field part of the period. the number of years in the period, zero if unsupported



hours
public static Period hours(int hours)(Code)
Create a period with a specified number of hours.

The standard period type is used, thus you can add other fields such as months or days using the withXxx() methods. For example, Period.hours(2).withMinutes(30);

If you want a hour-based period that cannot have other fields added, then you should consider using Hours .
Parameters:
  hours - the amount of hours in this period the period




millis
public static Period millis(int millis)(Code)
Create a period with a specified number of millis.

The standard period type is used, thus you can add other fields such as days or hours using the withXxx() methods. For example, Period.millis(20).withSeconds(30);
Parameters:
  millis - the amount of millis in this period the period




minus
public Period minus(ReadablePeriod period)(Code)
Returns a new period with the specified period subtracted.

Each field of the period is subtracted separately. Thus a period of 3 hours 30 minutes minus 2 hours 40 minutes will produce a result of 1 hour and -10 minutes - see Period.normalizedStandard() .

If the period being added contains a non-zero amount for a field that is not supported in this period then an exception is thrown.

This period instance is immutable and unaffected by this method call.
Parameters:
  period - the period to add, null adds zero and returns this the new updated period
throws:
  UnsupportedOperationException - if any field is not supported
since:
   1.5




minusDays
public Period minusDays(int days)(Code)
Returns a new period minus the specified number of days taken away.

This period instance is immutable and unaffected by this method call.
Parameters:
  days - the amount of days to take away, may be negative the new period minus the increased days
throws:
  UnsupportedOperationException - if the field is not supported




minusHours
public Period minusHours(int hours)(Code)
Returns a new period minus the specified number of hours taken away.

This period instance is immutable and unaffected by this method call.
Parameters:
  hours - the amount of hours to take away, may be negative the new period minus the increased hours
throws:
  UnsupportedOperationException - if the field is not supported




minusMillis
public Period minusMillis(int millis)(Code)
Returns a new period minus the specified number of millis taken away.

This period instance is immutable and unaffected by this method call.
Parameters:
  millis - the amount of millis to take away, may be negative the new period minus the increased millis
throws:
  UnsupportedOperationException - if the field is not supported




minusMinutes
public Period minusMinutes(int minutes)(Code)
Returns a new period minus the specified number of minutes taken away.

This period instance is immutable and unaffected by this method call.
Parameters:
  minutes - the amount of minutes to take away, may be negative the new period minus the increased minutes
throws:
  UnsupportedOperationException - if the field is not supported




minusMonths
public Period minusMonths(int months)(Code)
Returns a new period minus the specified number of months taken away.

This period instance is immutable and unaffected by this method call.
Parameters:
  months - the amount of months to take away, may be negative the new period minus the increased months
throws:
  UnsupportedOperationException - if the field is not supported




minusSeconds
public Period minusSeconds(int seconds)(Code)
Returns a new period minus the specified number of seconds taken away.

This period instance is immutable and unaffected by this method call.
Parameters:
  seconds - the amount of seconds to take away, may be negative the new period minus the increased seconds
throws:
  UnsupportedOperationException - if the field is not supported




minusWeeks
public Period minusWeeks(int weeks)(Code)
Returns a new period minus the specified number of weeks taken away.

This period instance is immutable and unaffected by this method call.
Parameters:
  weeks - the amount of weeks to take away, may be negative the new period minus the increased weeks
throws:
  UnsupportedOperationException - if the field is not supported




minusYears
public Period minusYears(int years)(Code)
Returns a new period with the specified number of years taken away.

This period instance is immutable and unaffected by this method call.
Parameters:
  years - the amount of years to take away, may be negative the new period with the increased years
throws:
  UnsupportedOperationException - if the field is not supported




minutes
public static Period minutes(int minutes)(Code)
Create a period with a specified number of minutes.

The standard period type is used, thus you can add other fields such as days or hours using the withXxx() methods. For example, Period.minutes(2).withSeconds(30);

If you want a minute-based period that cannot have other fields added, then you should consider using Minutes .
Parameters:
  minutes - the amount of minutes in this period the period




months
public static Period months(int months)(Code)
Create a period with a specified number of months.

The standard period type is used, thus you can add other fields such as years or days using the withXxx() methods. For example, Period.months(2).withDays(6);

If you want a month-based period that cannot have other fields added, then you should consider using Months .
Parameters:
  months - the amount of months in this period the period




normalizedStandard
public Period normalizedStandard()(Code)
Normalizes this period using standard rules, assuming a 12 month year, 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to normalize a period. However to achieve this it makes the assumption that all years are 12 months, all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds. This is not true when daylight savings time is considered, and may also not be true for some chronologies. However, it is included as it is a useful operation for many applications and business rules.

If the period contains years or months, then the months will be normalized to be between 0 and 11. The days field and below will be normalized as necessary, however this will not overflow into the months field. Thus a period of 1 year 15 months will normalize to 2 years 3 months. But a period of 1 month 40 days will remain as 1 month 40 days.

The result will always have a PeriodType of standard, thus days will be grouped into weeks. a normalized period equivalent to this period
throws:
  ArithmeticException - if any field is too large to be represented
since:
   1.5




normalizedStandard
public Period normalizedStandard(PeriodType type)(Code)
Normalizes this period using standard rules, assuming a 12 month year, 7 day week, 24 hour day, 60 minute hour and 60 second minute, providing control over how the result is split into fields.

This method allows you to normalize a period. However to achieve this it makes the assumption that all years are 12 months, all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds. This is not true when daylight savings time is considered, and may also not be true for some chronologies. However, it is included as it is a useful operation for many applications and business rules.

If the period contains years or months, then the months will be normalized to be between 0 and 11. The days field and below will be normalized as necessary, however this will not overflow into the months field. Thus a period of 1 year 15 months will normalize to 2 years 3 months. But a period of 1 month 40 days will remain as 1 month 40 days.

The PeriodType parameter controls how the result is created. It allows you to omit certain fields from the result if desired. For example, you may not want the result to include weeks, in which case you pass in PeriodType.yearMonthDayTime().
Parameters:
  type - the period type of the new period, null means standard type a normalized period equivalent to this period
throws:
  ArithmeticException - if any field is too large to be represented
throws:
  UnsupportedOperationException - if this period contains non-zeroyears or months but the specified period type does not support them
since:
   1.5




plus
public Period plus(ReadablePeriod period)(Code)
Returns a new period with the specified period added.

Each field of the period is added separately. Thus a period of 2 hours 30 minutes plus 3 hours 40 minutes will produce a result of 5 hours 70 minutes - see Period.normalizedStandard() .

If the period being added contains a non-zero amount for a field that is not supported in this period then an exception is thrown.

This period instance is immutable and unaffected by this method call.
Parameters:
  period - the period to add, null adds zero and returns this the new updated period
throws:
  UnsupportedOperationException - if any field is not supported
since:
   1.5




plusDays
public Period plusDays(int days)(Code)
Returns a new period plus the specified number of days added.

This period instance is immutable and unaffected by this method call.
Parameters:
  days - the amount of days to add, may be negative the new period plus the increased days
throws:
  UnsupportedOperationException - if the field is not supported




plusHours
public Period plusHours(int hours)(Code)
Returns a new period plus the specified number of hours added.

This period instance is immutable and unaffected by this method call.
Parameters:
  hours - the amount of hours to add, may be negative the new period plus the increased hours
throws:
  UnsupportedOperationException - if the field is not supported




plusMillis
public Period plusMillis(int millis)(Code)
Returns a new period plus the specified number of millis added.

This period instance is immutable and unaffected by this method call.
Parameters:
  millis - the amount of millis to add, may be negative the new period plus the increased millis
throws:
  UnsupportedOperationException - if the field is not supported




plusMinutes
public Period plusMinutes(int minutes)(Code)
Returns a new period plus the specified number of minutes added.

This period instance is immutable and unaffected by this method call.
Parameters:
  minutes - the amount of minutes to add, may be negative the new period plus the increased minutes
throws:
  UnsupportedOperationException - if the field is not supported




plusMonths
public Period plusMonths(int months)(Code)
Returns a new period plus the specified number of months added.

This period instance is immutable and unaffected by this method call.
Parameters:
  months - the amount of months to add, may be negative the new period plus the increased months
throws:
  UnsupportedOperationException - if the field is not supported




plusSeconds
public Period plusSeconds(int seconds)(Code)
Returns a new period plus the specified number of seconds added.

This period instance is immutable and unaffected by this method call.
Parameters:
  seconds - the amount of seconds to add, may be negative the new period plus the increased seconds
throws:
  UnsupportedOperationException - if the field is not supported




plusWeeks
public Period plusWeeks(int weeks)(Code)
Returns a new period plus the specified number of weeks added.

This period instance is immutable and unaffected by this method call.
Parameters:
  weeks - the amount of weeks to add, may be negative the new period plus the increased weeks
throws:
  UnsupportedOperationException - if the field is not supported




plusYears
public Period plusYears(int years)(Code)
Returns a new period with the specified number of years added.

This period instance is immutable and unaffected by this method call.
Parameters:
  years - the amount of years to add, may be negative the new period with the increased years
throws:
  UnsupportedOperationException - if the field is not supported




seconds
public static Period seconds(int seconds)(Code)
Create a period with a specified number of seconds.

The standard period type is used, thus you can add other fields such as days or hours using the withXxx() methods. For example, Period.seconds(2).withMillis(30);

If you want a second-based period that cannot have other fields added, then you should consider using Seconds .
Parameters:
  seconds - the amount of seconds in this period the period




toPeriod
public Period toPeriod()(Code)
Get this period as an immutable Period object by returning this. this



toStandardDays
public Days toStandardDays()(Code)
Converts this period to a period in days assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds. This is not true when daylight savings time is considered, and may also not be true for some unusual chronologies. However, it is included as it is a useful operation for many applications and business rules.

If the period contains years or months, an exception will be thrown. a period representing the number of standard days in this period
throws:
  UnsupportedOperationException - if the period contains years or months
throws:
  ArithmeticException - if the number of days is too large to be represented
since:
   1.5




toStandardDuration
public Duration toStandardDuration()(Code)
Converts this period to a duration assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert from a period to a duration. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds. This is not true when daylight savings time is considered, and may also not be true for some unusual chronologies. However, it is included as it is a useful operation for many applications and business rules.

If the period contains years or months, an exception will be thrown. a duration equivalent to this period
throws:
  UnsupportedOperationException - if the period contains years or months
since:
   1.5




toStandardHours
public Hours toStandardHours()(Code)
Converts this period to a period in hours assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds. This is not true when daylight savings time is considered, and may also not be true for some unusual chronologies. However, it is included as it is a useful operation for many applications and business rules.

If the period contains years or months, an exception will be thrown. a period representing the number of standard hours in this period
throws:
  UnsupportedOperationException - if the period contains years or months
throws:
  ArithmeticException - if the number of hours is too large to be represented
since:
   1.5




toStandardMinutes
public Minutes toStandardMinutes()(Code)
Converts this period to a period in minutes assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds. This is not true when daylight savings time is considered, and may also not be true for some unusual chronologies. However, it is included as it is a useful operation for many applications and business rules.

If the period contains years or months, an exception will be thrown. a period representing the number of standard minutes in this period
throws:
  UnsupportedOperationException - if the period contains years or months
throws:
  ArithmeticException - if the number of minutes is too large to be represented
since:
   1.5




toStandardSeconds
public Seconds toStandardSeconds()(Code)
Converts this period to a period in seconds assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds. This is not true when daylight savings time is considered, and may also not be true for some unusual chronologies. However, it is included as it is a useful operation for many applications and business rules.

If the period contains years or months, an exception will be thrown. a period representing the number of standard seconds in this period
throws:
  UnsupportedOperationException - if the period contains years or months
throws:
  ArithmeticException - if the number of seconds is too large to be represented
since:
   1.5




toStandardWeeks
public Weeks toStandardWeeks()(Code)
Converts this period to a period in weeks assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds. This is not true when daylight savings time is considered, and may also not be true for some unusual chronologies. However, it is included as it is a useful operation for many applications and business rules.

If the period contains years or months, an exception will be thrown. a period representing the number of standard weeks in this period
throws:
  UnsupportedOperationException - if the period contains years or months
throws:
  ArithmeticException - if the number of weeks is too large to be represented
since:
   1.5




weeks
public static Period weeks(int weeks)(Code)
Create a period with a specified number of weeks.

The standard period type is used, thus you can add other fields such as months or days using the withXxx() methods. For example, Period.weeks(2).withDays(6);

If you want a week-based period that cannot have other fields added, then you should consider using Weeks .
Parameters:
  weeks - the amount of weeks in this period the period




withDays
public Period withDays(int days)(Code)
Returns a new period with the specified number of days.

This period instance is immutable and unaffected by this method call.
Parameters:
  days - the amount of days to add, may be negative the new period with the increased days
throws:
  UnsupportedOperationException - if the field is not supported




withField
public Period withField(DurationFieldType field, int value)(Code)
Creates a new Period instance with the specified field set to a new value.

This period instance is immutable and unaffected by this method call.
Parameters:
  field - the field to set, not null
Parameters:
  value - the value to set to the new period instance
throws:
  IllegalArgumentException - if the field type is null or unsupported




withFieldAdded
public Period withFieldAdded(DurationFieldType field, int value)(Code)
Creates a new Period instance with the valueToAdd added to the specified field.

This period instance is immutable and unaffected by this method call.
Parameters:
  field - the field to set, not null
Parameters:
  value - the value to add the new period instance
throws:
  IllegalArgumentException - if the field type is null or unsupported




withFields
public Period withFields(ReadablePeriod period)(Code)
Creates a new Period instance with the fields from the specified period copied on top of those from this period.

This period instance is immutable and unaffected by this method call.
Parameters:
  period - the period to copy from, null ignored the new period instance
throws:
  IllegalArgumentException - if a field type is unsupported




withHours
public Period withHours(int hours)(Code)
Returns a new period with the specified number of hours.

This period instance is immutable and unaffected by this method call.
Parameters:
  hours - the amount of hours to add, may be negative the new period with the increased hours
throws:
  UnsupportedOperationException - if the field is not supported




withMillis
public Period withMillis(int millis)(Code)
Returns a new period with the specified number of millis.

This period instance is immutable and unaffected by this method call.
Parameters:
  millis - the amount of millis to add, may be negative the new period with the increased millis
throws:
  UnsupportedOperationException - if the field is not supported




withMinutes
public Period withMinutes(int minutes)(Code)
Returns a new period with the specified number of minutes.

This period instance is immutable and unaffected by this method call.
Parameters:
  minutes - the amount of minutes to add, may be negative the new period with the increased minutes
throws:
  UnsupportedOperationException - if the field is not supported




withMonths
public Period withMonths(int months)(Code)
Returns a new period with the specified number of months.

This period instance is immutable and unaffected by this method call.
Parameters:
  months - the amount of months to add, may be negative the new period with the increased months
throws:
  UnsupportedOperationException - if the field is not supported




withPeriodType
public Period withPeriodType(PeriodType type)(Code)
Creates a new Period instance with the same field values but different PeriodType.

This period instance is immutable and unaffected by this method call.
Parameters:
  type - the period type to use, null means standard the new period instance
throws:
  IllegalArgumentException - if the new period won't accept all of the current fields




withSeconds
public Period withSeconds(int seconds)(Code)
Returns a new period with the specified number of seconds.

This period instance is immutable and unaffected by this method call.
Parameters:
  seconds - the amount of seconds to add, may be negative the new period with the increased seconds
throws:
  UnsupportedOperationException - if the field is not supported




withWeeks
public Period withWeeks(int weeks)(Code)
Returns a new period with the specified number of weeks.

This period instance is immutable and unaffected by this method call.
Parameters:
  weeks - the amount of weeks to add, may be negative the new period with the increased weeks
throws:
  UnsupportedOperationException - if the field is not supported




withYears
public Period withYears(int years)(Code)
Returns a new period with the specified number of years.

This period instance is immutable and unaffected by this method call.
Parameters:
  years - the amount of years to add, may be negative the new period with the increased years
throws:
  UnsupportedOperationException - if the field is not supported




years
public static Period years(int years)(Code)
Create a period with a specified number of years.

The standard period type is used, thus you can add other fields such as months or days using the withXxx() methods. For example, Period.years(2).withMonths(6);

If you want a year-based period that cannot have other fields added, then you should consider using Years .
Parameters:
  years - the amount of years in this period the period




Methods inherited from org.joda.time.base.BasePeriod
protected void addField(DurationFieldType field, int value)(Code)(Java Doc)
protected void addFieldInto(int[] values, DurationFieldType field, int value)(Code)(Java Doc)
protected void addPeriod(ReadablePeriod period)(Code)(Java Doc)
protected int[] addPeriodInto(int[] values, ReadablePeriod period)(Code)(Java Doc)
protected PeriodType checkPeriodType(PeriodType type)(Code)(Java Doc)
public DurationFieldType getFieldType(int index)(Code)(Java Doc)
public PeriodType getPeriodType()(Code)(Java Doc)
public int getValue(int index)(Code)(Java Doc)
protected void mergePeriod(ReadablePeriod period)(Code)(Java Doc)
protected int[] mergePeriodInto(int[] values, ReadablePeriod period)(Code)(Java Doc)
protected void setField(DurationFieldType field, int value)(Code)(Java Doc)
protected void setFieldInto(int[] values, DurationFieldType field, int value)(Code)(Java Doc)
protected void setPeriod(ReadablePeriod period)(Code)(Java Doc)
protected void setPeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis)(Code)(Java Doc)
protected void setValue(int index, int value)(Code)(Java Doc)
protected void setValues(int[] values)(Code)(Java Doc)
public int size()(Code)(Java Doc)
public Duration toDurationFrom(ReadableInstant startInstant)(Code)(Java Doc)
public Duration toDurationTo(ReadableInstant endInstant)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.