33
44import WinSDK
55
6+ import struct Foundation. Date
7+
68private let SwiftDatePickerProc : SUBCLASSPROC = { ( hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData) in
79 let datepicker : DatePicker ? =
810 unsafeBitCast ( dwRefData, to: AnyObject . self) as? DatePicker
@@ -22,7 +24,40 @@ public class DatePicker: Control {
2224 private static let style : WindowStyle =
2325 ( base: WS_POPUP | WS_TABSTOP, extended: 0 )
2426
25- /// Configuring the Date Picker Style
27+ // MARK - Managing the Date and Calendar
28+
29+ /// The date displayed by the date picker.
30+ public var date : Date {
31+ get {
32+ var stDateTime : SYSTEMTIME = SYSTEMTIME ( )
33+ // FIXME(compnerd) ensure that GDT_VALID is returned
34+ _ = withUnsafeMutablePointer ( to: & stDateTime) {
35+ SendMessageW ( self . hWnd, UINT ( DTM_GETSYSTEMTIME) ,
36+ WPARAM ( 0 ) , LPARAM ( UInt ( bitPattern: $0) ) )
37+ }
38+
39+ let ftDateTime : FILETIME = FILETIME ( stDateTime)
40+ return Date ( timeIntervalSince1970: ftDateTime. timeIntervalSince1970)
41+ }
42+ set { self . setDate ( newValue, animated: false ) }
43+ }
44+
45+ /// Sets the date to display in the date picker, with an option to animate the
46+ /// setting.
47+ public func setDate( _ date: Date , animated: Bool ) {
48+ assert ( !animated, " not yet implemented " )
49+
50+ var ftSystemTime : FILETIME =
51+ FILETIME ( timeIntervalSince1970: date. timeIntervalSince1970)
52+ let stSystemTime : SYSTEMTIME = SYSTEMTIME ( ftSystemTime)
53+
54+ _ = withUnsafePointer ( to: stSystemTime) {
55+ SendMessageW ( self . hWnd, UINT ( DTM_SETSYSTEMTIME) ,
56+ WPARAM ( GDT_VALID) , LPARAM ( UInt ( bitPattern: $0) ) )
57+ }
58+ }
59+
60+ // MARK - Configuring the Date Picker Style
2661
2762 public private( set) var datePickerStyle : DatePickerStyle = . inline
2863 public private( set) var preferredDatePickerStyle : DatePickerStyle = . automatic {
0 commit comments