Skip to content

Commit

Permalink
Release 0.1.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiChenghan committed Jun 30, 2016
1 parent 6818934 commit 5bfdd1c
Show file tree
Hide file tree
Showing 112 changed files with 1,144 additions and 1,078 deletions.
4 changes: 2 additions & 2 deletions Addition.podspec
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "Addition"
s.version = "0.1.2"
s.version = "0.1.3"
s.summary = "ios扩展类集"

# This description is used to generate tags and improve search results.
Expand All @@ -32,7 +32,7 @@ Pod::Spec.new do |s|

s.source_files = 'Addition/*.{h,m}'
s.resource_bundles = {
'Addition' => ['Pod/Assets/*.png']

}

# s.public_header_files = 'Pod/Classes/**/*.h'
Expand Down
18 changes: 18 additions & 0 deletions Addition/NSDate+Addition.h
Expand Up @@ -107,4 +107,22 @@
*/
+(void)getSepTime:(NSTimeInterval)startTime endTime:(NSTimeInterval)endTime complete:(void(^)(NSString *sepTime , NSString *hour, NSString *minute, NSString *second))complete;

/**
* 获取时间间隔 -- 结束时间减去开始时间后间隔天时分秒;当不满1天的时候,则显示时分秒。
*
* @param startTime 开始时间戳 -- 以1970为基点
* @param endTime 结束时间戳 -- 以1790为基点
* @param complete 获取结果
*/

/**
* 获取时间间隔 -- 结束时间减去开始时间后间隔天时分秒;当不满1天的时候,则显示时分秒。
*
* @param maxDay 最大间隔天数 -- 例如2天,则间隔超过48小时的,则显示天(2天),否则显示小时(47);maxDay默认为2;当maxDay为0时,则时间间隔全部转换为时分秒,并不保留天!!!相当于getSepTime方法。
* @param startTime 开始时间戳 -- 以1970为基点
* @param endTime 结束时间戳 -- 以1790为基点
* @param complete 获取结果
*/
+(void)getSepTimeWithDay:(NSInteger)maxDay startTime:(NSTimeInterval)startTime endTime:(NSTimeInterval)endTime complete:(void(^)(NSString *sepTime, NSString *day, NSString *hour, NSString *minute, NSString *second))complete;

@end
203 changes: 131 additions & 72 deletions Addition/NSDate+Addition.m
Expand Up @@ -148,101 +148,160 @@ +(NSString *)getCurrentTime:(NSString *)string
*/
+(void)getSepTime:(NSTimeInterval)startTime endTime:(NSTimeInterval)endTime complete:(void(^)(NSString *sepTime , NSString *hour, NSString *minute, NSString *second))complete
{
[NSDate getSepTimeWithDay:0 startTime:startTime endTime:endTime complete:^(NSString *sepTime, NSString *day, NSString *hour, NSString *minute, NSString *second) {
complete(sepTime, hour, minute, second);
}];
}

/**
* 获取时间间隔 -- 结束时间减去开始时间后间隔天时分秒;当不满1天的时候,则显示时分秒。
*
* @param maxDay 最大间隔天数 -- 例如2天,则4间隔超过48小时的,则显示天(2天),否则显示小时(47);maxDay默认为2
* @param startTime 开始时间戳 -- 以1970为基点
* @param endTime 结束时间戳 -- 以1790为基点
* @param complete 获取结果
*/
+(void)getSepTimeWithDay:(NSInteger)maxDay startTime:(NSTimeInterval)startTime endTime:(NSTimeInterval)endTime complete:(void(^)(NSString *sepTime, NSString *day, NSString *hour, NSString *minute, NSString *second))complete
{
NSString *tpDay = @"";
NSString *tpHour = @"00";
NSString *tpMinute = @"00";
NSString *tpSecond = @"00";
NSString *tpSepTime = @"00:00:00";
NSInteger sepTimeInteger = (NSInteger)(endTime - startTime);

/**
* 如果时间间隔小于60,则直接显示
*/
if (sepTimeInteger < 60)
if (sepTimeInteger > 0)
{
if (sepTimeInteger < 10)
/**
* 如果时间间隔小于60,则直接显示
*/
if (sepTimeInteger < 60)
{
tpSecond = [NSString stringWithFormat:@"0%ld",(long)sepTimeInteger];
}
else
{
tpSecond = [NSString stringWithFormat:@"%ld",(long)sepTimeInteger];
}
}
else
{
NSInteger sepMinute = sepTimeInteger/60;
if (sepMinute < 60)
{
/**
* 时间间隔小于60分钟
*/
if (sepMinute < 10)
if (sepTimeInteger < 10)
{
tpMinute = [NSString stringWithFormat:@"0%ld",(long)sepMinute];
tpSecond = [NSString stringWithFormat:@"0%ld",(long)sepTimeInteger];
}
else
{
tpMinute = [NSString stringWithFormat:@"%ld",(long)sepMinute];
}

NSInteger sepSecond = sepTimeInteger - sepMinute*60;
if (sepSecond < 10)
{
tpSecond = [NSString stringWithFormat:@"0%ld",(long)sepSecond];
}
else
{
tpSecond = [NSString stringWithFormat:@"%ld",(long)sepSecond];
tpSecond = [NSString stringWithFormat:@"%ld",(long)sepTimeInteger];
}
}
else
{
/**
* 时间间隔大于60分钟
*/
NSInteger sepHour = sepTimeInteger/60/60;
sepMinute = (sepTimeInteger - sepHour*60*60)/60;
NSInteger sepSecond = sepTimeInteger - sepHour*60*60 - sepMinute*60;

/**
* 时
*/
if (sepHour < 10)
{
tpHour = [NSString stringWithFormat:@"0%ld",(long)sepHour];
}
else
{
tpHour = [NSString stringWithFormat:@"%ld",(long)sepHour];
}

/**
* 分
*/
if (sepMinute < 10)
{
tpMinute = [NSString stringWithFormat:@"0%ld",(long)sepMinute];
}
else
NSInteger sepMinute = sepTimeInteger/60;
if (sepMinute < 60)
{
tpMinute = [NSString stringWithFormat:@"%ld",(long)sepMinute];
}

/**
* 秒
*/
if (sepSecond < 10)
{
tpSecond = [NSString stringWithFormat:@"0%ld",(long)sepSecond];
/**
* 时间间隔小于60分钟
*/
if (sepMinute < 10)
{
tpMinute = [NSString stringWithFormat:@"0%ld",(long)sepMinute];
}
else
{
tpMinute = [NSString stringWithFormat:@"%ld",(long)sepMinute];
}

NSInteger sepSecond = sepTimeInteger - sepMinute*60;
if (sepSecond < 10)
{
tpSecond = [NSString stringWithFormat:@"0%ld",(long)sepSecond];
}
else
{
tpSecond = [NSString stringWithFormat:@"%ld",(long)sepSecond];
}
}
else
{
tpSecond = [NSString stringWithFormat:@"%ld",(long)sepSecond];
/**
* 时间间隔大于60分钟
*/
NSInteger sepHour = sepTimeInteger/60/60;
sepMinute = (sepTimeInteger - sepHour*60*60)/60;
NSInteger sepSecond = sepTimeInteger - sepHour*60*60 - sepMinute*60;

/**
* 时
*/
if (sepHour < 10)
{
tpHour = [NSString stringWithFormat:@"0%ld",(long)sepHour];
}
else
{
if (sepHour >= maxDay*24)
{
//大等于maxDay*24小时 -- 获取天
NSInteger sepDay = 0;
if (maxDay != 0)
{
sepDay = sepHour/24;
}
if (sepDay == 0)
{
tpDay = @"";
}
else
{
tpDay = [NSString stringWithFormat:@"%ld",(long)sepDay];
}
if ((sepHour - sepDay*24) < 10)
{
tpHour = [NSString stringWithFormat:@"0%ld",(long)(sepHour - sepDay*24)];
}
else
{
tpHour = [NSString stringWithFormat:@"%ld",(long)(sepHour - sepDay*24)];
}
}
else
{
//小于48小时,大于10小时
tpHour = [NSString stringWithFormat:@"%ld",(long)sepHour];
}
}

/**
* 分
*/
if (sepMinute < 10)
{
tpMinute = [NSString stringWithFormat:@"0%ld",(long)sepMinute];
}
else
{
tpMinute = [NSString stringWithFormat:@"%ld",(long)sepMinute];
}

/**
* 秒
*/
if (sepSecond < 10)
{
tpSecond = [NSString stringWithFormat:@"0%ld",(long)sepSecond];
}
else
{
tpSecond = [NSString stringWithFormat:@"%ld",(long)sepSecond];
}
}
}
}
tpSepTime = [NSString stringWithFormat:@"%@:%@:%@",tpHour,tpMinute,tpSecond];
complete(tpSepTime, tpHour, tpMinute, tpSecond);
//判断是否有天
if (tpDay.length > 0)
{
//有天
tpSepTime = [NSString stringWithFormat:@"%@ %@:%@:%@",tpDay,tpHour,tpMinute,tpSecond];
complete(tpSepTime, tpDay, tpHour, tpMinute, tpSecond);
}
else
{
//无天 -- 则直接显示
tpSepTime = [NSString stringWithFormat:@"%@:%@:%@",tpHour,tpMinute,tpSecond];
complete(tpSepTime, tpDay, tpHour, tpMinute, tpSecond);
}
}

@end

0 comments on commit 5bfdd1c

Please sign in to comment.