Skip to content

Commit

Permalink
Chinese , week Mon, Tue, Wed, Thu, Fri, Sat, Sun
Browse files Browse the repository at this point in the history
  • Loading branch information
Pikdays committed Dec 18, 2015
1 parent bf49844 commit 62591b8
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
17 changes: 17 additions & 0 deletions DateTools/DateTools.bundle/en.lproj/DateTools.strings
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,20 @@
"%dh" = "%dh"; // hour
"%dm" = "%dm"; // minute
"%ds" = "%ds"; // second

/* Week format for */
"Mon" = "Mon";
"Tue" = "Tue";
"Wed" = "Wed";
"Thu" = "Thu";
"Fri" = "Fri";
"Sat" = "Sat";
"Sun" = "Sun";

"周一" = "星期一";
"周二" = "星期二";
"周三" = "星期三";
"周四" = "星期四";
"周五" = "星期五";
"周六" = "星期六";
"周日" = "星期日";
17 changes: 17 additions & 0 deletions DateTools/DateTools.bundle/zh-Hans.lproj/DateTools.strings
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,20 @@
"%dh" = "%d小时"; // hour
"%dm" = "%d分"; // minute
"%ds" = "%d秒"; // second

/* Week format for */
"Mon" = "星期一";
"Tue" = "星期二";
"Wed" = "星期三";
"Thu" = "星期四";
"Fri" = "星期五";
"Sat" = "星期六";
"Sun" = "星期日";

"周一" = "星期一";
"周二" = "星期二";
"周三" = "星期三";
"周四" = "星期四";
"周五" = "星期五";
"周六" = "星期六";
"周日" = "星期日";
17 changes: 17 additions & 0 deletions DateTools/DateTools.bundle/zh-Hant.lproj/DateTools.strings
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,20 @@
"%dh" = "%d小時"; // hour
"%dm" = "%d分"; // minute
"%ds" = "%d秒"; // second

/* Week format for */
"Mon" = "星期壹";
"Tue" = "星期二";
"Wed" = "星期三";
"Thu" = "星期四";
"Fri" = "星期五";
"Sat" = "星期六";
"Sun" = "星期日";

"周壹" = "星期壹";
"周二" = "星期二";
"周三" = "星期三";
"周四" = "星期四";
"周五" = "星期五";
"周六" = "星期六";
"周日" = "星期日";
7 changes: 7 additions & 0 deletions DateTools/NSDate+DateTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ NSLocalizedStringFromTableInBundle(key, @"DateTools", [NSBundle bundleWithPath:[
#pragma mark - Time Ago
+ (NSString*)timeAgoSinceDate:(NSDate*)date;
+ (NSString*)shortTimeAgoSinceDate:(NSDate*)date;
+ (NSString *)weekTimeAgoSinceDate:(NSDate *)date;

- (NSString*)timeAgoSinceNow;
- (NSString *)shortTimeAgoSinceNow;
- (NSString *)weekTimeAgoSinceNow;

- (NSString *)timeAgoSinceDate:(NSDate *)date;
- (NSString *)timeAgoSinceDate:(NSDate *)date numericDates:(BOOL)useNumericDates;
- (NSString *)timeAgoSinceDate:(NSDate *)date numericDates:(BOOL)useNumericDates numericTimes:(BOOL)useNumericTimes;


- (NSString *)shortTimeAgoSinceDate:(NSDate *)date;
- (NSString *)weekTimeAgoSinceDate:(NSDate *)date;


#pragma mark - Date Components Without Calendar
Expand Down
26 changes: 24 additions & 2 deletions DateTools/NSDate+DateTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ typedef NS_ENUM(NSUInteger, DateAgoFormat){
DateAgoLongUsingNumericDatesAndTimes,
DateAgoLongUsingNumericDates,
DateAgoLongUsingNumericTimes,
DateAgoShort
DateAgoShort,
DateAgoWeek,
};

typedef NS_ENUM(NSUInteger, DateAgoValues){
Expand Down Expand Up @@ -95,6 +96,10 @@ + (NSString*)shortTimeAgoSinceDate:(NSDate*)date{
return [date shortTimeAgoSinceDate:[NSDate date]];
}

+ (NSString*)weekTimeAgoSinceDate:(NSDate*)date{
return [date weekTimeAgoSinceDate:[NSDate date]];
}

/**
* Returns a string with the most convenient unit of time representing
* how far in the past that date is from now.
Expand All @@ -115,6 +120,10 @@ - (NSString *)shortTimeAgoSinceNow{
return [self shortTimeAgoSinceDate:[NSDate date]];
}

- (NSString *)weekTimeAgoSinceNow{
return [self weekTimeAgoSinceDate:[NSDate date]];
}

- (NSString *)timeAgoSinceDate:(NSDate *)date{
return [self timeAgoSinceDate:date numericDates:NO];
}
Expand All @@ -139,6 +148,10 @@ - (NSString *)shortTimeAgoSinceDate:(NSDate *)date{
return [self timeAgoSinceDate:date format:DateAgoShort];
}

- (NSString *)weekTimeAgoSinceDate:(NSDate *)date{
return [self timeAgoSinceDate:date format:DateAgoWeek];
}

- (NSString *)timeAgoSinceDate:(NSDate *)date format:(DateAgoFormat)format {

NSCalendar *calendar = [NSCalendar currentCalendar];
Expand Down Expand Up @@ -185,7 +198,8 @@ - (NSString *)localizedStringFor:(DateAgoFormat)format valueType:(DateAgoValues)
BOOL isShort = format == DateAgoShort;
BOOL isNumericDate = format == DateAgoLongUsingNumericDates || format == DateAgoLongUsingNumericDatesAndTimes;
BOOL isNumericTime = format == DateAgoLongUsingNumericTimes || format == DateAgoLongUsingNumericDatesAndTimes;

BOOL isWeek = format == DateAgoWeek;

switch (valueType) {
case YearsAgo:
if (isShort) {
Expand Down Expand Up @@ -221,6 +235,14 @@ - (NSString *)localizedStringFor:(DateAgoFormat)format valueType:(DateAgoValues)
if (isShort) {
return [self logicLocalizedStringFromFormat:@"%%d%@d" withValue:value];
} else if (value >= 2) {
if (isWeek && value <= 7) {
NSDateFormatter *dayDateFormatter = [[NSDateFormatter alloc]init];
dayDateFormatter.dateFormat = @"EEE";
NSString *eee = [dayDateFormatter stringFromDate:self];

return DateToolsLocalizedStrings(eee);
}

return [self logicLocalizedStringFromFormat:@"%%d %@days ago" withValue:value];
} else if (isNumericDate) {
return DateToolsLocalizedStrings(@"1 day ago");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ - (void)viewDidLoad
//Setup date formatter
self.formatter = [[NSDateFormatter alloc] init];
[self.formatter setDateFormat:@"HHmm MMMM d yyyy"];



// <<<<<<<<<<<<<<<<<<<<<<<
self.selectedDate = [NSDate dateWithTimeIntervalSinceNow:-24*60*60*6+100];
NSString *week = [NSDate weekTimeAgoSinceDate:self.selectedDate];
NSLog(@"Week:%@", week);
// >>>>>>>>>>>>>>>>>>>>>>>


//Set initial date
self.selectedDate = [self.formatter dateFromString:@"0000 November 5 1605"];
Expand Down

0 comments on commit 62591b8

Please sign in to comment.