1

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. :)

Novarg
  • 7,390
  • 3
  • 38
  • 74

1 Answers1

1

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.

mattjgalloway
  • 34,792
  • 12
  • 100
  • 110
  • hi, thanks for your answer. It is sort of a long-term planner. Like "I want to achieve that and that in `y` years and `m` months". So that's why I need these years and months. And it looks like `NSDateComponents` is what I was looking for. Going to check it tomorrow(or today if I will have time after fixing one bug). – Novarg Feb 15 '12 at 11:34