Swiftpack.co - ahmedelserafy7/FBDateFormat as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
ahmedelserafy7/FBDateFormat
FBDateFormat is an algorithmic library that helps developers use Facebook date format in thier application with hassle-free conversion.
.package(url: "https://github.com/ahmedelserafy7/FBDateFormat.git", from: "1.0.1")

FBDateFormat

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. 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

CocoaPods

You can use CocoaPods by adding the following line to your Podfile:

pod 'FBDateFormat'

How it works

  • 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())

Usage

  1. First things first, all you have to do is to import it:
import FBDateFormat
  1. 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.


Contributions and support

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.

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

GitHub

link
Stars: 0
Last commit: 4 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics