Hi xnav
Sorry Just wanted to ask another issue, it related to the same my issue bit other question
I don't want to open a new topic for it
I have a code now just upgraded it 🙂
The first target, I need calculate range between start and current date and time and first move my progressview ahead to this date.
On second part of my method I realized if (progV.progress == 1.0) I mean by that progressbar finished current period and need to start new one.
So I am recognizing how much days in a month and adding a new period by day count. I am not sure I realized it well, my billing range starting at 25 day each month and ending at 24 day next month. I conted days in current month. You can see it in my code. I'll be glad if you can help me with it and explain this subject.
Bacause I don't know when User will open this billing.
So I have to use some abstract date and time
Myabe someone else can help me with this issue
here is my code
- (void)viewDidLoad {
[super viewDidLoad];
NSDate *currentDate = [NSDate date];
//self.destDate = [NSDate dateWithTimeIntervalSinceNow:2];
self.destDate = [NSDate dateWithTimeIntervalSince1970:1369342800];
self.totalTime = [self.destDate timeIntervalSinceNow];
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(updateProgressDate)
userInfo:nil
repeats:YES];
float timeRange = [self.destDate timeIntervalSinceDate:currentDate];
progV.progress = timeRange;
}
-(void)updateProgressDate {
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [cal components:units fromDate:[NSDate date] toDate:self->destDate options:0];
[dateLabel setText:[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c %d%c", [components month], 'm', [components day], 'd', [components hour], 'h', [components minute], 'm', [components second], 's']];
NSDate *now = [NSDate date];
float progress = 1 - [self.destDate timeIntervalSinceNow]/self.totalTime;
progV.progress = progress;
//NSLog(@"%f", progress);
if (progV.progress == 1.0) {
//calculate how much days in current month
NSCalendar *cal = [NSCalendar currentCalendar];
NSRange rng = [cal rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:[NSDate date]];
NSUInteger numberOfDaysInMonth = rng.length;
// end calculating
NSLog(@"%d", numberOfDaysInMonth);
if (numberOfDaysInMonth == 31) {
self.destDate = [now dateByAddingTimeInterval:60*60*24*31];
} else if (numberOfDaysInMonth == 30) {
self.destDate = [now dateByAddingTimeInterval:60*60*24*30];
} else if (numberOfDaysInMonth == 29) {
self.destDate = [now dateByAddingTimeInterval:60*60*24*29];
} else {
self.destDate = [now dateByAddingTimeInterval:60*60*24*28];
}
self.totalTime = [self.destDate timeIntervalSinceNow];
progV.progress= 0;
progV.progress=progress;
NSLog(@"%@", now);
NSLog(@"Progress is already 1.0!");
}
}