]>
Commit | Line | Data |
---|---|---|
36d07f78 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/osx/cocoa/private/date.h | |
3 | // Purpose: NSDate-related helpers | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2011-12-19 | |
36d07f78 VZ |
6 | // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org> |
7 | // Licence: wxWindows licence | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_OSX_COCOA_PRIVATE_DATE_H_ | |
11 | #define _WX_OSX_COCOA_PRIVATE_DATE_H_ | |
12 | ||
13 | #include "wx/datetime.h" | |
14 | ||
15 | namespace wxOSXImpl | |
16 | { | |
17 | ||
18 | // Functions to convert between NSDate and wxDateTime. | |
19 | ||
20 | // Returns an NSDate corresponding to the given wxDateTime which can be invalid | |
21 | // (in which case nil is returned). | |
22 | inline NSDate* NSDateFromWX(const wxDateTime& dt) | |
23 | { | |
24 | if ( !dt.IsValid() ) | |
25 | return nil; | |
26 | ||
27 | // Get the internal representation as a double used by NSDate. | |
28 | double ticks = dt.GetValue().ToDouble(); | |
29 | ||
30 | // wxDateTime uses milliseconds while NSDate uses (fractional) seconds. | |
31 | return [NSDate dateWithTimeIntervalSince1970:ticks/1000.]; | |
32 | } | |
33 | ||
34 | ||
35 | // Returns wxDateTime corresponding to the given NSDate (which may be nil). | |
36 | inline wxDateTime NSDateToWX(const NSDate* d) | |
37 | { | |
38 | if ( !d ) | |
39 | return wxDefaultDateTime; | |
40 | ||
41 | // Reverse everything done above. | |
42 | wxLongLong ll; | |
43 | ll.Assign([d timeIntervalSince1970]*1000); | |
44 | wxDateTime dt(ll); | |
45 | return dt; | |
46 | } | |
47 | ||
48 | } // namespace wxOSXImpl | |
49 | ||
50 | #endif // _WX_OSX_COCOA_PRIVATE_DATE_H_ |