summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWonYoung Choi <wy80.choi@samsung.com>2016-09-26 11:23:33 +0900
committerWonYoung Choi <wy80.choi@samsung.com>2016-09-26 11:23:33 +0900
commit54b82fc7b450f6e2e4fa2d6ff718d663f64b7404 (patch)
tree6a9420692c3c76e437a22ae861c897104f1429a0
parent3cd0d0df81daa0d5f369463fbb0c433d52597eee (diff)
downloadelm-sharp-54b82fc7b450f6e2e4fa2d6ff718d663f64b7404.tar.gz
elm-sharp-54b82fc7b450f6e2e4fa2d6ff718d663f64b7404.tar.bz2
elm-sharp-54b82fc7b450f6e2e4fa2d6ff718d663f64b7404.zip
Add additional fields to structure SystemTime representing struct tm
Change-Id: Ib44aa8ada3be508edbe9dbbfb8b94ff9087e7d6e
-rw-r--r--ElmSharp/ElmSharp/Calendar.cs29
-rw-r--r--ElmSharp/ElmSharp/DateTimeSelector.cs41
-rw-r--r--ElmSharp/Interop/Interop.Elementary.CalendarView.cs8
-rw-r--r--ElmSharp/Interop/Interop.Elementary.DateTimePicker.cs25
-rw-r--r--ElmSharp/Interop/Interop.Libc.cs42
5 files changed, 65 insertions, 80 deletions
diff --git a/ElmSharp/ElmSharp/Calendar.cs b/ElmSharp/ElmSharp/Calendar.cs
index e577159..b7fa77b 100644
--- a/ElmSharp/ElmSharp/Calendar.cs
+++ b/ElmSharp/ElmSharp/Calendar.cs
@@ -105,13 +105,13 @@ namespace ElmSharp
{
get
{
- var tm = new Interop.Elementary.tm();
- Interop.Elementary.elm_calendar_selected_time_get(Handle, out tm);
- return ConvertToDateTime(tm);
+ var tm = new Interop.Libc.SystemTime();
+ Interop.Elementary.elm_calendar_selected_time_get(Handle, ref tm);
+ return tm;
}
set
{
- var tm = ConvertToTM(value);
+ Interop.Libc.SystemTime tm = value;
Interop.Elementary.elm_calendar_selected_time_set(Handle, ref tm);
_cacheSelectedDate = value;
}
@@ -134,27 +134,6 @@ namespace ElmSharp
return Interop.Elementary.elm_calendar_add(parent.Handle);
}
- private static DateTime ConvertToDateTime(Interop.Elementary.tm tm)
- {
- DateTime date = new DateTime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
- return date;
- }
-
- private static Interop.Elementary.tm ConvertToTM(DateTime date)
- {
- Interop.Elementary.tm tm = new Interop.Elementary.tm();
- tm.tm_sec = date.Second;
- tm.tm_min = date.Minute;
- tm.tm_hour = date.Hour;
- tm.tm_mday = date.Day;
- tm.tm_mon = date.Month - 1;
- tm.tm_year = date.Year - 1900;
- tm.tm_wday = (int)date.DayOfWeek;
- tm.tm_yday = date.DayOfYear;
- tm.tm_isdst = date.IsDaylightSavingTime() ? 1 : 0;
- return tm;
- }
-
static private void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
{
managedArray = new string[size];
diff --git a/ElmSharp/ElmSharp/DateTimeSelector.cs b/ElmSharp/ElmSharp/DateTimeSelector.cs
index 9327c75..5cb1cb4 100644
--- a/ElmSharp/ElmSharp/DateTimeSelector.cs
+++ b/ElmSharp/ElmSharp/DateTimeSelector.cs
@@ -46,13 +46,13 @@ namespace ElmSharp
{
get
{
- var tm = new Interop.Elementary.tm();
+ var tm = new Interop.Libc.SystemTime();
Interop.Elementary.elm_datetime_value_max_get(Handle, ref tm);
- return ConvertToDateTime(tm);
+ return tm;
}
set
{
- var tm = ConvertToTM(value);
+ Interop.Libc.SystemTime tm = value;
Interop.Elementary.elm_datetime_value_max_set(Handle, ref tm);
}
}
@@ -61,13 +61,13 @@ namespace ElmSharp
{
get
{
- var tm = new Interop.Elementary.tm();
+ var tm = new Interop.Libc.SystemTime();
Interop.Elementary.elm_datetime_value_min_get(Handle, ref tm);
- return ConvertToDateTime(tm);
+ return tm;
}
set
{
- var tm = ConvertToTM(value);
+ Interop.Libc.SystemTime tm = value;
Interop.Elementary.elm_datetime_value_min_set(Handle, ref tm);
}
}
@@ -76,13 +76,13 @@ namespace ElmSharp
{
get
{
- var tm = new Interop.Elementary.tm();
+ var tm = new Interop.Libc.SystemTime();
Interop.Elementary.elm_datetime_value_get(Handle, ref tm);
- return ConvertToDateTime(tm);
+ return tm;
}
set
{
- var tm = ConvertToTM(value);
+ Interop.Libc.SystemTime tm = value;
Interop.Elementary.elm_datetime_value_set(Handle, ref tm);
_cacheDateTime = value;
}
@@ -90,7 +90,7 @@ namespace ElmSharp
public bool IsFieldVisible(DateTimeFieldType type)
{
- return Interop.Elementary.elm_datetime_field_visible_get(Handle, (int) type);
+ return Interop.Elementary.elm_datetime_field_visible_get(Handle, (int)type);
}
public void SetFieldLimit(DateTimeFieldType type, int minimum, int maximum)
@@ -107,26 +107,5 @@ namespace ElmSharp
{
return Interop.Elementary.elm_datetime_add(parent.Handle);
}
-
- DateTime ConvertToDateTime(Interop.Elementary.tm tm)
- {
- DateTime date = new DateTime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
- return date;
- }
-
- Interop.Elementary.tm ConvertToTM(DateTime date)
- {
- Interop.Elementary.tm tm = new Interop.Elementary.tm();
- tm.tm_sec = date.Second;
- tm.tm_min = date.Minute;
- tm.tm_hour = date.Hour;
- tm.tm_mday = date.Day;
- tm.tm_mon = date.Month - 1;
- tm.tm_year = date.Year - 1900;
- tm.tm_wday = (int)date.DayOfWeek;
- tm.tm_yday = date.DayOfYear;
- tm.tm_isdst = date.IsDaylightSavingTime() ? 1 : 0;
- return tm;
- }
}
}
diff --git a/ElmSharp/Interop/Interop.Elementary.CalendarView.cs b/ElmSharp/Interop/Interop.Elementary.CalendarView.cs
index b48c8c4..33c03b7 100644
--- a/ElmSharp/Interop/Interop.Elementary.CalendarView.cs
+++ b/ElmSharp/Interop/Interop.Elementary.CalendarView.cs
@@ -21,10 +21,10 @@ internal static partial class Interop
internal static extern void elm_calendar_min_max_year_get(IntPtr obj, out int min, out int max);
[DllImport(Libraries.Elementary)]
- internal static extern void elm_calendar_selected_time_set(IntPtr obj, ref tm selectedtime);
+ internal static extern void elm_calendar_selected_time_set(IntPtr obj, ref Libc.SystemTime selectedtime);
[DllImport(Libraries.Elementary)]
- internal static extern void elm_calendar_selected_time_get(IntPtr obj, out tm selectedtime);
+ internal static extern void elm_calendar_selected_time_get(IntPtr obj, ref Libc.SystemTime selectedtime);
[DllImport(Libraries.Elementary)]
internal static extern void elm_calendar_first_day_of_week_set(IntPtr obj, int day);
@@ -39,7 +39,7 @@ internal static partial class Interop
internal static extern int elm_calendar_selectable_get(IntPtr obj);
[DllImport(Libraries.Elementary)]
- internal static extern bool elm_calendar_displayed_time_get(IntPtr obj, out tm displayedtime);
+ internal static extern bool elm_calendar_displayed_time_get(IntPtr obj, out Libc.SystemTime displayedtime);
[DllImport(Libraries.Elementary)]
internal static extern void elm_calendar_interval_set(IntPtr obj, double interval);
@@ -47,4 +47,4 @@ internal static partial class Interop
[DllImport(Libraries.Elementary)]
internal static extern double elm_calendar_interval_get(IntPtr obj);
}
-} \ No newline at end of file
+}
diff --git a/ElmSharp/Interop/Interop.Elementary.DateTimePicker.cs b/ElmSharp/Interop/Interop.Elementary.DateTimePicker.cs
index 759e0dd..6cb1e3e 100644
--- a/ElmSharp/Interop/Interop.Elementary.DateTimePicker.cs
+++ b/ElmSharp/Interop/Interop.Elementary.DateTimePicker.cs
@@ -17,10 +17,10 @@ internal static partial class Interop
internal static extern IntPtr elm_datetime_add(IntPtr obj);
[DllImport(Libraries.Elementary)]
- internal static extern bool elm_datetime_value_set(IntPtr obj, ref tm newtime);
+ internal static extern bool elm_datetime_value_set(IntPtr obj, ref Libc.SystemTime newtime);
[DllImport(Libraries.Elementary)]
- internal static extern bool elm_datetime_value_get(IntPtr obj, ref tm currtime);
+ internal static extern bool elm_datetime_value_get(IntPtr obj, ref Libc.SystemTime currtime);
[DllImport(Libraries.Elementary)]
internal static extern bool elm_datetime_format_set(IntPtr obj, string format);
@@ -35,16 +35,16 @@ internal static partial class Interop
}
[DllImport(Libraries.Elementary)]
- internal static extern bool elm_datetime_value_max_set(IntPtr obj, ref tm maxtime);
+ internal static extern bool elm_datetime_value_max_set(IntPtr obj, ref Libc.SystemTime maxtime);
[DllImport(Libraries.Elementary)]
- internal static extern bool elm_datetime_value_max_get(IntPtr obj, ref tm maxtime);
+ internal static extern bool elm_datetime_value_max_get(IntPtr obj, ref Libc.SystemTime maxtime);
[DllImport(Libraries.Elementary)]
- internal static extern bool elm_datetime_value_min_set(IntPtr obj, ref tm mintime);
+ internal static extern bool elm_datetime_value_min_set(IntPtr obj, ref Libc.SystemTime mintime);
[DllImport(Libraries.Elementary)]
- internal static extern bool elm_datetime_value_min_get(IntPtr obj, ref tm mintime);
+ internal static extern bool elm_datetime_value_min_get(IntPtr obj, ref Libc.SystemTime mintime);
[DllImport(Libraries.Elementary)]
internal static extern void elm_datetime_field_limit_set(IntPtr obj, int type, int min, int max);
@@ -58,19 +58,6 @@ internal static partial class Interop
[DllImport(Libraries.Elementary)]
internal static extern bool elm_datetime_field_visible_get(IntPtr obj, int type);
- [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
- internal struct tm
- {
- public int tm_sec;
- public int tm_min;
- public int tm_hour;
- public int tm_mday;
- public int tm_mon;
- public int tm_year;
- public int tm_wday;
- public int tm_yday;
- public int tm_isdst;
- }
internal enum DateTimeFieldType
{
Year,
diff --git a/ElmSharp/Interop/Interop.Libc.cs b/ElmSharp/Interop/Interop.Libc.cs
index b01ae6d..af32e20 100644
--- a/ElmSharp/Interop/Interop.Libc.cs
+++ b/ElmSharp/Interop/Interop.Libc.cs
@@ -1,4 +1,4 @@
-// Copyright 2016 by Samsung Electronics, Inc.,
+// Copyright 2016 by Samsung Electronics, Inc.,
//
// This software is the confidential and proprietary information
// of Samsung Electronics, Inc. ("Confidential Information"). You
@@ -15,5 +15,45 @@ internal static partial class Interop
{
[DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
internal static extern int Free(IntPtr ptr);
+
+ // Broken-down time is stored in the structure tm which is defined in <time.h> as follows:
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct SystemTime
+ {
+ public int tm_sec;
+ public int tm_min;
+ public int tm_hour;
+ public int tm_mday;
+ public int tm_mon;
+ public int tm_year;
+ public int tm_wday;
+ public int tm_yday;
+ public int tm_isdst;
+
+ // The glibc version of struct tm has additional fields
+ public long tm_gmtoff;
+ public IntPtr tm_zone;
+
+ public static implicit operator SystemTime(DateTime value)
+ {
+ SystemTime tm = new SystemTime();
+ tm.tm_sec = value.Second;
+ tm.tm_min = value.Minute;
+ tm.tm_hour = value.Hour;
+ tm.tm_mday = value.Day;
+ tm.tm_mon = value.Month - 1;
+ tm.tm_year = value.Year - 1900;
+ tm.tm_wday = (int)value.DayOfWeek;
+ tm.tm_yday = value.DayOfYear;
+ tm.tm_isdst = value.IsDaylightSavingTime() ? 1 : 0;
+ return tm;
+ }
+
+ public static implicit operator DateTime(SystemTime value)
+ {
+ DateTime date = new DateTime(value.tm_year + 1900, value.tm_mon + 1, value.tm_mday, value.tm_hour, value.tm_min, value.tm_sec);
+ return date;
+ }
+ }
}
}