]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/cocoa/private/date.h
Don't create multiple parent-less top level frames in layout sample.
[wxWidgets.git] / include / wx / osx / cocoa / private / date.h
CommitLineData
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
6// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $
7// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_OSX_COCOA_PRIVATE_DATE_H_
12#define _WX_OSX_COCOA_PRIVATE_DATE_H_
13
14#include "wx/datetime.h"
15
16namespace wxOSXImpl
17{
18
19// Functions to convert between NSDate and wxDateTime.
20
21// Returns an NSDate corresponding to the given wxDateTime which can be invalid
22// (in which case nil is returned).
23inline NSDate* NSDateFromWX(const wxDateTime& dt)
24{
25 if ( !dt.IsValid() )
26 return nil;
27
28 // Get the internal representation as a double used by NSDate.
29 double ticks = dt.GetValue().ToDouble();
30
31 // wxDateTime uses milliseconds while NSDate uses (fractional) seconds.
32 return [NSDate dateWithTimeIntervalSince1970:ticks/1000.];
33}
34
35
36// Returns wxDateTime corresponding to the given NSDate (which may be nil).
37inline wxDateTime NSDateToWX(const NSDate* d)
38{
39 if ( !d )
40 return wxDefaultDateTime;
41
42 // Reverse everything done above.
43 wxLongLong ll;
44 ll.Assign([d timeIntervalSince1970]*1000);
45 wxDateTime dt(ll);
46 return dt;
47}
48
49} // namespace wxOSXImpl
50
51#endif // _WX_OSX_COCOA_PRIVATE_DATE_H_