From e19589491db1a0a92455dbf03223352d6908969f Mon Sep 17 00:00:00 2001 From: Maria Ines Casadei Date: Fri, 19 Dec 2014 12:26:20 -0300 Subject: [PATCH] Date formatted --- EyeTypeChat/MockedData.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/EyeTypeChat/MockedData.swift b/EyeTypeChat/MockedData.swift index 82b43bf..c9cd091 100644 --- a/EyeTypeChat/MockedData.swift +++ b/EyeTypeChat/MockedData.swift @@ -36,6 +36,7 @@ class MockedData { var currentDate: NSDate? = NSDate(); var msg01 = Message.createMessage("Hi Mary!", sentDateTime: currentDate!, conversation: bffConversation, fromContact: nil, entity: "Message", context: dataContext) + currentDate = MockedData.dateByAddingMinutes(1, date: currentDate) var msg02 = Message.createMessage("How are you?", sentDateTime: currentDate!, conversation: bffConversation, fromContact: nil, entity: "Message", context: dataContext) currentDate = MockedData.dateByAddingMinutes(1, date: currentDate) @@ -101,6 +102,7 @@ class MockedData { if let fetchResults = dataContext.executeFetchRequest(fetchRequest, error: nil) as? [TelegramAccount] { let contacts = fetchResults[0].contacts + println("Contact list") for contact in contacts! { if let eachContact = contact as? Contact { println("Contact Name: \(eachContact.name). Phone Number: \(eachContact.phoneNumber)") @@ -117,12 +119,16 @@ class MockedData { var sortedMsgs : [Message] = msgsArray sortedMsgs.sort({$0.sentDateTime.timeIntervalSinceNow < $1.sentDateTime.timeIntervalSinceNow}) + let dateStringFormatter = NSDateFormatter() + dateStringFormatter.dateFormat = "yyyy-MM-dd hh:mm" + for msg in sortedMsgs{ + let sentFormattedDate = dateStringFormatter.stringFromDate(msg.sentDateTime) var messageDetails: String if let from = msg.fromContact{ - messageDetails = "Message: \(msg.text). From: \(msg.fromContact!.name). Sent: \(msg.sentDateTime)." + messageDetails = "Message: \(msg.text). From: \(msg.fromContact!.name). Sent: \(sentFormattedDate)." }else{ - messageDetails = "Message: \(msg.text). From: me. Sent: \(msg.sentDateTime)." + messageDetails = "Message: \(msg.text). From: me. Sent: \(sentFormattedDate)." } println(messageDetails) }