-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 移除无用的类型字段(暂时不考虑除文字之外的类型支持), 改为时间显示
- Loading branch information
qwertyyb
committed
Oct 26, 2019
1 parent
32490ca
commit 421d16c
Showing
7 changed files
with
75 additions
and
39 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
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
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
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
This file was deleted.
Oops, something went wrong.
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,53 @@ | ||
// | ||
// SummaryTransformer.swift | ||
// YPaste | ||
// | ||
// Created by 虚幻 on 2019/9/7. | ||
// Copyright © 2019 qwertyyb. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
class SummaryTransformer: ValueTransformer { | ||
override func transformedValue(_ value: Any?) -> Any? { | ||
if (value == nil) { return value } | ||
let str = value as! String | ||
let trimmedTitle = str.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) | ||
return trimmedTitle | ||
} | ||
} | ||
|
||
class TimeTransformer: ValueTransformer { | ||
override func transformedValue(_ value: Any?) -> Any? { | ||
if value == nil { return value } | ||
let date = value as! Date | ||
let ts = lround(-date.timeIntervalSinceNow) | ||
let s = ts % 60 | ||
let m = Int(ts / 60) % 60 | ||
let h = Int(ts / 3600) % 24 | ||
let d = Int(ts / 3600 / 24) | ||
var output = "" | ||
if d > 0 { output += "\(d)天" } | ||
if d > 2 { | ||
let formatter = DateFormatter() | ||
formatter.dateFormat = "HH:mm MM-dd" | ||
return formatter.string(from: date) | ||
} | ||
if h > 0 { output += "\(h)小时" } | ||
if d > 0 { | ||
return output + "前" | ||
} | ||
if m > 0 { output += "\(m)分" } | ||
if h > 0 { | ||
return output + "前" | ||
} | ||
if s > 0 { output += "\(s)秒" } | ||
return output + "前" | ||
} | ||
} | ||
|
||
extension NSValueTransformerName { | ||
static let summaryTransformerName = NSValueTransformerName(rawValue: "SummaryTransformer") | ||
static let timeTransformerName = NSValueTransformerName(rawValue: "TimeTransformer") | ||
} | ||
|
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