66//
77
88import SwiftUI
9+ import MobileCoreServices
910
1011struct MykeMode : View {
1112
12- // @State private var selectedDate: Date = Date(timeIntervalSince1970: TimeInterval(1639239835))
13- // @State private var selectedDate: Date = Date(timeIntervalSince1970: TimeInterval(1631892600))
13+ // @State private var selectedDate: Date = Date(timeIntervalSince1970: TimeInterval(1639239835))
14+ // @State private var selectedDate: Date = Date(timeIntervalSince1970: TimeInterval(1631892600))
1415
1516 @Binding var selectedDate : Date
16- @Binding var selectedTimeZone : String
17+ @Binding var selectedTimeZone : TimeZone
1718
1819 @State private var selectedFormatStyle : DateFormat = dateFormats [ 0 ]
1920
@@ -24,25 +25,43 @@ struct MykeMode: View {
2425 TimeZone ( identifier: " Europe/Budapest " ) !,
2526 ]
2627
28+ @State private var showCopied : Bool = false
29+
30+ #if os(iOS)
31+ // @State private var selectionFeedbackGenerator: UISelectionFeedbackGenerator? = nil
32+ @State private var notificationFeedbackGenerator : UINotificationFeedbackGenerator ? = nil
33+ #endif
34+
2735 func selectedTimeInZone( _ zone: TimeZone ) -> String {
2836 let df = DateFormatter ( )
2937 df. dateStyle = . none
3038 df. timeStyle = . short
3139 df. timeZone = zone
3240 df. locale = Locale ( identifier: " en/us " )
33- return df. string ( from: convert ( date: selectedDate, from: TimeZone ( identifier: selectedTimeZone) !, to: TimeZone . current) )
41+ return df. string ( from: convert ( date: selectedDate, from: selectedTimeZone, to: TimeZone . current) )
42+ }
43+
44+ func generateTimesAndFlagsText( ) -> String {
45+ var text = " \n "
46+ for tz in selectedTimeZones {
47+ let abbr = fudgedAbbreviation ( for: tz) ?? " "
48+ text += " \( flagForTimeZone ( tz) ) - \( selectedTimeInZone ( tz) ) \( abbr) \n "
49+ }
50+ return text
3451 }
3552
3653 var body : some View {
3754
3855 NavigationView {
3956
4057 ScrollView ( showsIndicators: true ) {
41- DateTimeZonePicker ( selectedDate: $selectedDate, selectedTimeZone: $selectedTimeZone)
4258
43- Text ( " Time Zones: " )
44- . font ( . headline)
45- . frame ( minWidth: 0 , maxWidth: . infinity, alignment: . leading)
59+ Group {
60+
61+ DateTimeZonePicker ( selectedDate: $selectedDate, selectedTimeZone: $selectedTimeZone, showDate: false )
62+
63+ }
64+ . padding ( . horizontal, 8 )
4665
4766 List {
4867 ForEach ( selectedTimeZones, id: \. self) { tz in
@@ -66,8 +85,40 @@ struct MykeMode: View {
6685 . listStyle ( PlainListStyle ( ) )
6786 . scaledToFill ( )
6887
88+ Button ( action: {
89+ #if os(iOS)
90+ notificationFeedbackGenerator = UINotificationFeedbackGenerator ( )
91+ notificationFeedbackGenerator? . prepare ( )
92+ #endif
93+ UIPasteboard . general. setValue ( generateTimesAndFlagsText ( ) ,
94+ forPasteboardType: kUTTypePlainText as String )
95+ withAnimation {
96+ showCopied = true
97+ #if os(iOS)
98+ notificationFeedbackGenerator? . notificationOccurred ( . success)
99+ #endif
100+ }
101+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 1 ) {
102+ withAnimation {
103+ showCopied = false
104+ }
105+ #if os(iOS)
106+ notificationFeedbackGenerator = nil
107+ #endif
108+ }
109+ } ) {
110+ Text ( showCopied ? " Copied ✓ " : " Copy Times & Flags " )
111+ . font ( . headline)
112+ . foregroundColor ( . white)
113+ }
114+ . padding ( . horizontal)
115+ . padding ( . vertical, 5 )
116+ . background (
117+ RoundedRectangle ( cornerRadius: 15 , style: . continuous)
118+ . fill ( Color . accentColor)
119+ )
120+
69121 }
70- . padding ( . horizontal)
71122 . navigationTitle ( " Myke Mode " )
72123 . navigationBarTitleDisplayMode ( . inline)
73124 }
@@ -97,6 +148,6 @@ struct MykeMode: View {
97148
98149struct MykeMode_Previews : PreviewProvider {
99150 static var previews : some View {
100- MykeMode ( selectedDate: . constant( Date ( ) ) , selectedTimeZone: . constant( " America/Los_Angeles " ) )
151+ MykeMode ( selectedDate: . constant( Date ( ) ) , selectedTimeZone: . constant( TimeZone ( identifier : " America/Los_Angeles " ) ! ) )
101152 }
102153}
0 commit comments