Commit 59d925bd authored by Chris Graham's avatar Chris Graham

Matching v11 timestamp call conventions

parent b1473f9a
......@@ -8,22 +8,26 @@ import java.util.Locale;
CMS_Timestamps
get_timezoned_date(int timestamp, bool includeTime) - turns a unix timestamp into a written date or date&time, in the phone's timezone
get_timezoned_date_time(int timestamp) - turns a unix timestamp into a written date&time, in the phone's timezone
get_timezoned_date(int timestamp) - turns a unix timestamp into a written date, in the phone's timezone
int time() - returns unix timestamp
*/
public class CMS_Timestamps {
public static String get_timezoned_date(long timestamp, boolean includeTime) {
public static String get_timezoned_date_time(long timestamp) {
SimpleDateFormat df;
if (includeTime) {
df = new SimpleDateFormat("MMM dd, yyyy - HH:mm:ss", Locale.getDefault());
}
else {
df = new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault());
}
df = new SimpleDateFormat("MMM dd, yyyy - HH:mm:ss", Locale.getDefault());
return df.format(new Date(timestamp));
}
public static String get_timezoned_date(long timestamp) {
SimpleDateFormat df;
df = new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault());
return df.format(new Date(timestamp));
}
......
......@@ -14,11 +14,11 @@ public class CMS_Timestamps_Test {
String expectedOutput = "Feb 09, 2016 - 06:13:59";
System.out.println(CMS_Timestamps.get_timezoned_date(timestamp, true));
assertTrue(expectedOutput.equals(CMS_Timestamps.get_timezoned_date(timestamp, true)));
System.out.println(CMS_Timestamps.get_timezoned_date_time(timestamp));
assertTrue(expectedOutput.equals(CMS_Timestamps.get_timezoned_date_time(timestamp)));
String expectedOutputWithoutTime = "Feb 09, 2016";
assertTrue(expectedOutputWithoutTime.equals(CMS_Timestamps.get_timezoned_date(timestamp, false)));
assertTrue(expectedOutputWithoutTime.equals(CMS_Timestamps.get_timezoned_date(timestamp)));
}
}
......@@ -10,7 +10,8 @@
CMS_Timestamps
get_timezoned_date(int timestamp, bool includeTime) - turns a unix timestamp into a written date or date&time, in the phone's timezone
get_timezoned_date_time(int timestamp) - turns a unix timestamp into a written date&time, in the phone's timezone
get_timezoned_date(int timestamp) - turns a unix timestamp into a written date, in the phone's timezone
int time() - returns unix timestamp
*/
......@@ -19,7 +20,8 @@
@interface CMS_Timestamps : NSObject
+ (NSString *)get_timezoned_date:(int)timestamp :(BOOL)includeTime;
+ (NSString *)get_timezoned_date_time:(int)timestamp;
+ (NSString *)get_timezoned_date:(int)timestamp;
+ (int)time;
@end
......@@ -11,23 +11,34 @@
@implementation CMS_Timestamps
/**
* Turns a unix timestamp into a written date or date&time, in the phone's timezone
* Turns a unix timestamp into a written date&time, in the phone's timezone
*
* @param timestamp unix timestamp to be converted
* @param includeTime should time be considered from the timestamp ? YES - consider time, NO - discard time
*
* @return String representation of the supplied timestamp
*/
+ (NSString *)get_timezoned_date:(int)timestamp :(BOOL)includeTime{
+ (NSString *)get_timezoned_date_time:(int)timestamp{
NSDate *localDate = [NSDate dateWithTimeIntervalSince1970:timestamp];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
if (includeTime) {
[dateFormatter setDateFormat:@"MMM dd, yyyy - HH:mm:ss"];
}
else{
[dateFormatter setDateFormat:@"MMM dd, yyyy"];
}
[dateFormatter setDateFormat:@"MMM dd, yyyy - HH:mm:ss"];
return [dateFormatter stringFromDate:localDate];
}
/**
* Turns a unix timestamp into a written date, in the phone's timezone
*
* @param timestamp unix timestamp to be converted
* @param includeTime should time be considered from the timestamp ? YES - consider time, NO - discard time
*
* @return String representation of the supplied timestamp
*/
+ (NSString *)get_timezoned_date:(int)timestamp{
NSDate *localDate = [NSDate dateWithTimeIntervalSince1970:timestamp];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"MMM dd, yyyy"];
return [dateFormatter stringFromDate:localDate];
}
......
......@@ -31,9 +31,9 @@
{
int timestamp = 1427209581;
NSString *expectedOutput = @"Mar 24, 2015 - 20:36:21";
XCTAssertTrue([expectedOutput isEqualToString:[CMS_Timestamps get_timezoned_date:timestamp :YES]]);
XCTAssertTrue([expectedOutput isEqualToString:[CMS_Timestamps get_timezoned_date_time:timestamp]]);
NSString *expectedOutputWithoutTime = @"Mar 24, 2015";
XCTAssertTrue([expectedOutputWithoutTime isEqualToString:[CMS_Timestamps get_timezoned_date:timestamp :NO]]);
XCTAssertTrue([expectedOutputWithoutTime isEqualToString:[CMS_Timestamps get_timezoned_date:timestamp]]);
}
- (void)test_time
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment