Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahmedelserafy7/fbdateformat
FBDateFormat is an algorithmic library that helps developers use Facebook date format in thier application with hassle-free conversion.
https://github.com/ahmedelserafy7/fbdateformat
date dateformat dateformatter datetime facebook ios swift
Last synced: about 1 month ago
JSON representation
FBDateFormat is an algorithmic library that helps developers use Facebook date format in thier application with hassle-free conversion.
- Host: GitHub
- URL: https://github.com/ahmedelserafy7/fbdateformat
- Owner: ahmedelserafy7
- License: mit
- Created: 2021-08-30T14:51:27.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-23T06:59:03.000Z (about 3 years ago)
- Last Synced: 2024-10-15T04:04:59.996Z (2 months ago)
- Topics: date, dateformat, dateformatter, datetime, facebook, ios, swift
- Language: Swift
- Homepage:
- Size: 92.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FBDateFormat
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.
## Installation
### Using the Swift Package Manager
FBDateFormat is distributed using the [Swift Package Manager](https://swift.org/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:
```swift
import FBDateFormat
```### CocoaPods
You can use [CocoaPods](https://cocoapods.org) by adding the following line to your `Podfile`:
```ruby
pod 'FBDateFormat'
```## How it works
- Test Just now:
```swift
let currentDate = Date()
print(currentDate.displayFBDateFormat())
```- Test minutes:
```swift
let minsAgo: Double = -60let timeAgo = Date(timeIntervalSinceNow: minsAgo)
//let timeAgo = Date(timeIntervalSinceNow: 2 * minsAgo)
print(timeAgo.displayFBDateFormat())
```- Test hours:
```swift
let hrAgo: Double = 60 * minsAgolet timeAgo = Date(timeIntervalSinceNow: hrAgo)
//let timeAgo = Date(timeIntervalSinceNow: 2 * hrAgo)
print(timeAgo.displayFBDateFormat())
```- Test yesterday
```swift
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?
```swift
let timeAgo = Date(timeIntervalSinceNow: dayAgo + 3 * hrAgo)
print(timeAgo.displayFBDateFormat())
```- It still doesn't exceed the day before yesterday till now:
```swift
let timeAgo = Date(timeIntervalSinceNow: dayAgo + 3 * hrAgo + 50 * minsAgo)
print(timeAgo.displayFBDateFormat())
```- It exceeded yesterday:
```swift
let timeAgo = Date(timeIntervalSinceNow: dayAgo + 3 * hrAgo + minsAgo * 51)
print(timeAgo.displayFBDateFormat())
```- Test days:
```swift
let timeAgo = Date(timeIntervalSinceNow: 2 * dayAgo)
print(timeAgo.displayFBDateFormat())
```- Test weeks:
```swift
let weekAgo = 7 * dayAgolet timeAgo = Date(timeIntervalSinceNow: weekAgo)
print(timeAgo.displayFBDateFormat())
```
- Test months:```swift
let monthAgo = 4 * weekAgolet timeAgo = Date(timeIntervalSinceNow: monthAgo)
print(timeAgo.displayFBDateFormat())
```
- Test years:```swift
let yearAgo = 12 * monthAgolet timeAgo = Date(timeIntervalSinceNow: yearAgo)
//let timeAgo = Date(timeIntervalSinceNow: 5 * yearAgo)
print(timeAgo.displayFBDateFormat())
```## Usage
1. First things first, all you have to do is to import it:
```swift
import FBDateFormat
```
2. Use `displayFBDateFormat` function with your `Date` data types like `postDate.displayFBDateFormat()` or `commentDate.displayFBDateFormat()`.### Note:
You can check/try all test cases which can be found in [`/FBDateFormatExample`](https://github.com/ahmedelserafy7/FBDateFormat/tree/master/FBDateFormatExample/FBDateFormatExample).---
## Contributions and support
Having trouble working with FBDateFormat? Found a typo in the implementation? Interested in adding a feature or [fixing a bug](https://github.com/ahmedelserafy7/FBDateFormat/issues)? Then by all means [submit an issue](https://github.com/ahmedelserafy7/FBDateFormat/issues/new) or [pull request](https://help.github.com/articles/using-pull-requests/). If this is your first pull request, it may be helpful to read up on the [GitHub Flow](https://guides.github.com/introduction/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.### Pull Requests
When submitting a pull request:
1. Clone the repo.
2. Create a branch off of `master` and give it a meaningful name (e.g. `my-awesome-new-feature`).
3. Open a pull request on GitHub and describe the feature or fix.---
## Credits
### Creator
**Ahmed Elserafy**
-