//
//  NSDateComponents+OJAKit.m
//  OJAKitDemo
//
//  Created by luxiaoming on 16/7/7.
//  Copyright © 2016年 luxiaoming. All rights reserved.
//

#import "NSDateComponents+OJAKit.h"

@implementation NSDateComponents (OJAKit)

- (BOOL)oja_isEqualToDateComponents:(NSDateComponents *)dateComponents {
    if (self.year == dateComponents.year
        && self.month == dateComponents.month
        && self.day == dateComponents.day) {
        return YES;
    } else {
        return NO;
    }
}


+ (NSDateComponents *)monthBeforeTargetMonth:(NSDateComponents *)targetMonth {
    NSDateComponents *previousDateComponents = [[NSDateComponents alloc] init];
    NSInteger year = targetMonth.year;
    NSInteger month = targetMonth.month - 1;
    if (month == 0) {
        month = 12;
        year = year - 1;
    }
    previousDateComponents.year = year;
    previousDateComponents.month = month;
    previousDateComponents.day = 1;
    return previousDateComponents;
}

+ (NSDateComponents *)monthAfterTargetMonth:(NSDateComponents *)targetMonth {
    NSDateComponents *nextDateComponents = [[NSDateComponents alloc] init];
    NSInteger year = targetMonth.year;
    NSInteger month = targetMonth.month + 1;
    if (month == 13) {
        month = 1;
        year = year + 1;
    }
    
    nextDateComponents.year = year;
    nextDateComponents.month = month;
    nextDateComponents.day = 1;
    return nextDateComponents;
}

@end
