Search code examples
javaobjective-cjodatimeperiod

Time period in Objective-C


Doing a small project I have received some Java code that I should rewrite into Objective-C(for iPhone to be precise). I came across this piece of code:

public class Period {
  private org.joda.time.Period jodaPeriod;
  public Period(org.joda.time.Period jodaPeriod) {
    Validate.isTrue(PeriodType.standard().equals(jodaPeriod.getPeriodType()),
            "The jodaPeriod argument must be a standard type period");
    this.jodaPeriod = jodaPeriod;
  }

  public Period(int months) {
    this(new org.joda.time.Period(months / 12, months % 12, 0, 0, 0, 0, 0, 0));
  }

  public Period(int years, int months) {
    this(new org.joda.time.Period(years, months, 0, 0, 0, 0, 0, 0));
  }
  //some other code
}

After a quick research I got the basics of the JodaTime period, but I still don't know how to do that in Objective-C. I've read about CMTime, but it's not really what I was looking for.

Thank you, any help would be greatly appreciated. :)


Solution

  • I'm not entirely sure what you're trying to use this for, but you'll want to look at:

    1. NSCalendar

    2. NSDateComponents

    3. NSDate

    If you give more information about what you're actually trying to achieve, we can explain how you'd use these.