Skip to content

Commit 31d9525

Browse files
committed
fix 0 padding
1 parent 19a83c1 commit 31d9525

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

MMQreki/MMQreki.m

+22-22
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ @implementation MMQreki
2626
#pragma mark -------------------------------------------------------
2727

2828
- (void)initializeTable {
29-
29+
3030
self.replaceTable = [@[@[@611,@2350],
3131
@[@468,@3222],
3232
@[@316,@7317],
@@ -59,10 +59,10 @@ - (void)initializeTable {
5959
@[@356,@3366],
6060
@[@572,@3475],
6161
@[@442,@1450]] mutableCopy];
62-
62+
6363
self.maxDays = [@[@31,@28,@31,@30,@31,@30,@31,@31,@30,@31,@30,@31] mutableCopy];
6464
self.oldTable = [@[@14] mutableCopy];
65-
65+
6666
if (!self.dateFormatter) {
6767
self.dateFormatter = [[NSDateFormatter alloc] init];
6868
self.dateFormatter.dateFormat = @"yyyy/MM/dd";
@@ -74,11 +74,11 @@ - (void)initializeTable {
7474
#pragma mark -------------------------------------------------------
7575

7676
- (NSString *)getOldToNewCalender:(NSDate *)oldDate {
77-
77+
7878
[self initializeTable];
79-
79+
8080
NSString *oldDateString = [self.dateFormatter stringFromDate:oldDate];
81-
81+
8282
NSNumber *newYear, *newMonth, *newDay, *tmp, *dofNewYear;
8383
NSNumber *oyy = @([[oldDateString substringToIndex:4] intValue]);
8484
NSNumber *omm = @([[oldDateString substringWithRange:NSMakeRange(5, 2)] intValue]);
@@ -117,30 +117,30 @@ - (NSString *)getOldToNewCalender:(NSDate *)oldDate {
117117
if ([newDay intValue] < 0) {
118118
return nil;
119119
}
120-
return [NSString stringWithFormat:@"%@/%@/%@", newYear, newMonth, newDay];
120+
return [NSString stringWithFormat:@"%@/%02d/%02d", oyy, [omm intValue], [odd intValue]];
121121
}
122122

123123
- (NSString *)getNewToOldCalender:(NSDate *)newDate {
124-
124+
125125
[self initializeTable];
126-
126+
127127
NSString *newDateString = [self.dateFormatter stringFromDate:newDate];
128-
128+
129129
NSNumber *oyy, *omm, *odd, *uruu, *DofNyy;
130130
NSNumber *nyy = @([[newDateString substringToIndex:4] intValue]);
131131
NSNumber *nmm = @([[newDateString substringWithRange:NSMakeRange(5, 2)] intValue]);
132132
NSNumber *ndd = @([[newDateString substringFromIndex:8] intValue]);
133-
133+
134134
DofNyy = [self numberDays:nyy month:nmm day:ndd];
135135
oyy = nyy;
136136
[self tableExpand:oyy];
137-
137+
138138
if ([DofNyy intValue] < [self.oldTable[0][0] intValue]) {
139139
oyy = @([oyy intValue] -1);
140140
DofNyy = @([DofNyy intValue] + 365 + [[self leapYear:oyy] intValue]);
141141
[self tableExpand:oyy];
142142
}
143-
143+
144144
for (int i = 12; i >= 0; i--) {
145145
if (![self.oldTable[i][1] isEqualToNumber:@0]) {
146146
if ([self.oldTable[i][0] intValue] <= [DofNyy intValue]) {
@@ -150,7 +150,7 @@ - (NSString *)getNewToOldCalender:(NSDate *)newDate {
150150
}
151151
}
152152
}
153-
153+
154154
if ([omm intValue] < 0) {
155155
uruu = @1;
156156
omm = @([omm intValue] - [omm intValue]);
@@ -162,19 +162,19 @@ - (NSString *)getNewToOldCalender:(NSDate *)newDate {
162162
}
163163

164164
- (NSString *)getRokuyo:(NSDate *)newDate {
165-
165+
166166
NSArray *rokuyo = @[@"大安",@"赤口",@"先勝",@"友引",@"先負",@"仏滅"];
167-
167+
168168
NSString *oldCal = [self getNewToOldCalender:newDate];
169169
NSArray *sepCal = [oldCal componentsSeparatedByString:@"/"];
170170
NSInteger oldMonth = [sepCal[1] intValue];
171171
NSInteger oldDay = [sepCal[2] intValue];
172-
172+
173173
NSInteger md = oldMonth + oldDay;
174174
float index = md % 6;
175-
175+
176176
NSString *roku = rokuyo[(int)index];
177-
177+
178178
return roku;
179179
}
180180

@@ -193,7 +193,7 @@ - (NSNumber *)leapYear:(NSNumber *)year {
193193
- (NSNumber *)numberDays:(NSNumber *)year month:(NSNumber *)month day:(NSNumber *)day {
194194

195195
self.maxDays[1] = @(28 + [[self leapYear:year] intValue]);
196-
196+
197197
NSNumber *days = day;
198198
for (int i = 1; i < [month intValue]; i++) {
199199
days = @([days intValue] + [self.maxDays[i-1] intValue]);
@@ -204,12 +204,12 @@ - (NSNumber *)numberDays:(NSNumber *)year month:(NSNumber *)month day:(NSNumber
204204
- (void)tableExpand:(NSNumber *)year {
205205

206206
NSNumber *ommax, *days, *uruu, *bit;
207-
207+
208208
days = self.replaceTable[[year intValue] - minDate][0];
209209
bit = self.replaceTable[[year intValue] - minDate][1];
210210
uruu = @([days intValue] % 13);
211211
days = @(floor([days intValue] / 13 + 0.001));
212-
212+
213213
self.oldTable[0] = @[days, @1];
214214
if ([uruu isEqualToNumber:@0]) {
215215
bit = @([bit intValue] * 2);

0 commit comments

Comments
 (0)