Welcome to FBDateFormat, an algorithmic library. I've built this library to help developers use Facebook date format in thier application with hassle-free conversion.
FBDateFormat is distributed using the Swift Package Manager. To install it into a project, go to file -> Swift Packages -> add it as a package dependency, then enter a package repository url which is https://github.com/ahmedelserafy7/FBDateFormat.git
, click next and one more next, and finish.
Then import FBDateFormat wherever you’d like to use it:
import FBDateFormat
You can use CocoaPods by adding the following line to your Podfile
:
pod 'FBDateFormat'
- Test Just now:
let currentDate = Date()
print(currentDate.displayFBDateFormat())
- Test minutes:
let minsAgo: Double = -60
let timeAgo = Date(timeIntervalSinceNow: minsAgo)
//let timeAgo = Date(timeIntervalSinceNow: 2 * minsAgo)
print(timeAgo.displayFBDateFormat())
- Test hours:
let hrAgo: Double = 60 * minsAgo
let timeAgo = Date(timeIntervalSinceNow: hrAgo)
//let timeAgo = Date(timeIntervalSinceNow: 2 * hrAgo)
print(timeAgo.displayFBDateFormat())
- Test yesterday
let dayAgo: Double = 24 * hrAgo
let timeAgo = Date(timeIntervalSinceNow: dayAgo)
print(timeAgo.displayFBDateFormat())
- Let's say today is "30/8 at 3:50 AM". How could I still be at yesterday?
let timeAgo = Date(timeIntervalSinceNow: dayAgo + 3 * hrAgo)
print(timeAgo.displayFBDateFormat())
- It still doesn't exceed the day before yesterday till now:
let timeAgo = Date(timeIntervalSinceNow: dayAgo + 3 * hrAgo + 50 * minsAgo)
print(timeAgo.displayFBDateFormat())
- It exceeded yesterday:
let timeAgo = Date(timeIntervalSinceNow: dayAgo + 3 * hrAgo + minsAgo * 51)
print(timeAgo.displayFBDateFormat())
- Test days:
let timeAgo = Date(timeIntervalSinceNow: 2 * dayAgo)
print(timeAgo.displayFBDateFormat())
- Test weeks:
let weekAgo = 7 * dayAgo
let timeAgo = Date(timeIntervalSinceNow: weekAgo)
print(timeAgo.displayFBDateFormat())
- Test months:
let monthAgo = 4 * weekAgo
let timeAgo = Date(timeIntervalSinceNow: monthAgo)
print(timeAgo.displayFBDateFormat())
- Test years:
let yearAgo = 12 * monthAgo
let timeAgo = Date(timeIntervalSinceNow: yearAgo)
//let timeAgo = Date(timeIntervalSinceNow: 5 * yearAgo)
print(timeAgo.displayFBDateFormat())
- First things first, all you have to do is to import it:
import FBDateFormat
- Use
displayFBDateFormat
function with yourDate
data types likepostDate.displayFBDateFormat()
orcommentDate.displayFBDateFormat()
.
You can check/try all test cases which can be found in /FBDateFormatExample
.
Having trouble working with FBDateFormat? Found a typo in the implementation? Interested in adding a feature or fixing a bug? Then by all means submit an issue or pull request. If this is your first pull request, it may be helpful to read up on the GitHub Flow first.
Please keep this in mind when requesting features and/or submitting pull requests:
- FBDateFormat is developed completely in the open, and your contributions are more than welcome.
- FBDateFormat has been designed as a base for you to customize and fit your
Date
data types easily. - It’s highly recommended that you spend a few minutes familiarizing yourself with its internal implementation, so that you’ll be ready to tackle any issues or edge cases that you might encounter.
When submitting a pull request:
- Clone the repo.
- Create a branch off of
master
and give it a meaningful name (e.g.my-awesome-new-feature
). - Open a pull request on GitHub and describe the feature or fix.
Ahmed Elserafy