mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-07 19:22:51 -04:00

* webview controller * ZimFilesOpened title * ZimFilesOpened * GridBasics * ZimFilesNew * GridCommon * ZimFilesDownloads * downloads * refactor * DownloadTaskCell * ZimFilesDownloads * CellBackground * zim file downloads * opened iconName * FlavorTag * grid sizing * ZimFileGrid * app icon * itunes file sharing * photo permission * mac about * About * about * app integration * LibrarySettings * Capsule * library setting * zim file backup setting * backup * ZimFileContextMenu * background fetch * update library * BackgroundTasks * library refresh * last refresh * LanguageSelector * language * LanguageSelector table * LibrarySettings macos * fetchLanguages * iOS LanguageSelector * sorting mode * library setting * ZimFilesNew * SettingSection * about * navigationTitle * background task identifier * setting * Settings * SettingSection * about macos * library version * language filter * rename * empty view * grid * ZimFileDetail * ZimFileDetailPanel * window sizing * opened zim file bottom * refresh * refresh * page zoom command * library * page zoom * split reader files * command and focus * focus and commands * open file in reader * frame * refactoring * refactor * languages * remove env object * refactor library view model * delete download task * downloads database op * service workers * service worker warning * hides service worker files * SearchFilter * url / UI * macos reader title * LibraryViewModel.reopen * remove search field * search focus * search keyboard shortcut * open multiple files * animations * refactor * search * sheet * SheetView library * sheet view style * zimfile list * reorg * style * LanguageSelector * ios setting * LibrarySettings * background task * delete alert * move * open in place, open main page * library refresh refactor * open bookmark throws * zim file missing * locate file * ZimFileMissingIndicator * predicates * observed zim file * macos build * icons * library refactor * menu refactor * refactor * html parser
52 lines
1.4 KiB
Swift
52 lines
1.4 KiB
Swift
//
|
|
// Formatter.swift
|
|
// Kiwix
|
|
//
|
|
// Created by Chris Li on 6/28/22.
|
|
// Copyright © 2022 Chris Li. All rights reserved.
|
|
//
|
|
|
|
class Formatter {
|
|
static let dateShort: DateFormatter = {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .short
|
|
formatter.timeStyle = .none
|
|
return formatter
|
|
}()
|
|
|
|
static let dateMedium: DateFormatter = {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .medium
|
|
formatter.timeStyle = .none
|
|
return formatter
|
|
}()
|
|
|
|
static let size: ByteCountFormatter = {
|
|
let formatter = ByteCountFormatter()
|
|
formatter.countStyle = .file
|
|
return formatter
|
|
}()
|
|
|
|
static let number: NumberFormatter = {
|
|
let formatter = NumberFormatter()
|
|
formatter.numberStyle = .decimal
|
|
return formatter
|
|
}()
|
|
|
|
static let percent: NumberFormatter = {
|
|
let formatter = NumberFormatter()
|
|
formatter.numberStyle = .percent
|
|
return formatter
|
|
}()
|
|
|
|
static func largeNumber(_ value: Int64) -> String {
|
|
let sign = ((value < 0) ? "-" : "" )
|
|
let abs = Swift.abs(value)
|
|
guard abs >= 1000 else {return "\(sign)\(abs)"}
|
|
let exp = Int(log10(Double(abs)) / log10(1000))
|
|
let units = ["K", "M", "G", "T", "P", "E"]
|
|
let rounded = round(10 * Double(abs) / pow(1000.0,Double(exp))) / 10;
|
|
return "\(sign)\(rounded)\(units[exp-1])"
|
|
}
|
|
}
|