This repository has been archived by the owner on Mar 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from 4alltecnologia/develop
Develop
- Loading branch information
Showing
25 changed files
with
959 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// Date+Extension.swift | ||
// UtilitiesCore | ||
// | ||
// Created by Luca Saldanha Schifino on 07/08/19. | ||
// Copyright © 2019 4all. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension Date { | ||
|
||
/// String describing elapsed time from date to now. | ||
var brazilianElapsedInterval: String { | ||
let interval = Calendar.current.dateComponents([.year, .month, .day, .hour], from: self, to: Date()) | ||
|
||
if let year = interval.year, year > 0 { | ||
return year == 1 ? "há \(year)" + " " + "ano" : | ||
"há \(year)" + " " + "anos" | ||
} else if let month = interval.month, month > 0 { | ||
return month == 1 ? "há \(month)" + " " + "mês" : | ||
"há \(month)" + " " + "meses" | ||
} else if let day = interval.day, day > 0 { | ||
return day == 1 ? "há \(day)" + " " + "dia" : | ||
"há \(day)" + " " + "dias" | ||
} else if let hour = interval.hour, hour > 0 { | ||
return hour == 1 ? "há \(hour)" + " " + "hora" : | ||
"há \(hour)" + " " + "horas" | ||
} else { | ||
return "agora" | ||
} | ||
} | ||
|
||
/// Returns String from date. | ||
/// | ||
/// - Parameters: | ||
/// - format: Date format. | ||
/// - timezone: TimeZone for the date. If none is passed, the device's locale is used. | ||
/// - Returns: Date's String. | ||
func getString(withFormat format: String, andTimezoneAbbreviation abbreviation: String? = nil) -> String { | ||
let dateFormatter = DateFormatter() | ||
if let abbreviation = abbreviation { | ||
dateFormatter.timeZone = TimeZone(abbreviation: abbreviation) | ||
} | ||
dateFormatter.dateFormat = format | ||
return dateFormatter.string(from: self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// Float+Extension.swift | ||
// UtilitiesCore | ||
// | ||
// Created by Luca Saldanha Schifino on 22/03/2018. | ||
// Copyright © 2019 4all. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension Float { | ||
|
||
/// Returns Float's String value with comma and two decimals. | ||
var cleanValue: String { | ||
return String(format: "%.2f",self).replacingOccurrences(of: ".", with: ",") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Int+Extension.swift | ||
// UtilitiesCore | ||
// | ||
// Created by Betina Pereira de Farias on 03/12/18. | ||
// Copyright © 2019 4all. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension Int { | ||
|
||
/// Returns price String from cents. | ||
var priceStringFromCents: String? { | ||
let formatter = NumberFormatter.brazilianCurrencyFormatter | ||
let amountFloat = Float(self) | ||
let price = amountFloat/100 | ||
guard let priceString = formatter.string(from: NSNumber(value: price)) else { | ||
return nil | ||
} | ||
return priceString | ||
} | ||
|
||
/// Returns the Int's representation on a badge. | ||
var badgeValue: String? { | ||
if self > 99 { | ||
return "99+" | ||
} else if self <= 0 { | ||
return nil | ||
} | ||
return String(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.