[gnumeric] New functions DATE2HDATE, DATE2HDATE_HEB and DATE2JULIAN.



commit 4f07925ae19095aadb8db2c3b232e8cd1c67e9ce
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Wed Jul 7 14:37:44 2010 -0600

    New functions DATE2HDATE, DATE2HDATE_HEB and DATE2JULIAN.
    
    2010-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* plugin.xml.in: new functions DATE2HDATE, DATE2HDATE_HEB, and
    	  DATE2JULIAN
    	* functions.c: ditto
    	(gnumeric_date_get_date): new
    
    2010-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* functions.c (help_networkdays): fix argument description
    	(help_workday): ditto

 NEWS                                 |    1 +
 plugins/fn-date/ChangeLog            |    5 +
 plugins/fn-date/functions.c          |    4 +-
 plugins/fn-hebrew-date/ChangeLog     |    7 ++
 plugins/fn-hebrew-date/functions.c   |  135 ++++++++++++++++++++++++++++++++++
 plugins/fn-hebrew-date/plugin.xml.in |    3 +
 6 files changed, 153 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index bc511e3..9b3e45b 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ Andreas:
 	* Improve the presentation of the examples in the function
 	  documentation. [#623455]
 	* Fix HDATE and friends. [#623764]
+	* New functions DATE2HDATE, DATE2HDATE_HEB and DATE2JULIAN.
 
 Jean:
 	* Fix strong/weak cursor display. [#623241]
diff --git a/plugins/fn-date/ChangeLog b/plugins/fn-date/ChangeLog
index f312073..728db38 100644
--- a/plugins/fn-date/ChangeLog
+++ b/plugins/fn-date/ChangeLog
@@ -1,5 +1,10 @@
 2010-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* functions.c (help_networkdays): fix argument description
+	(help_workday): ditto
+
+2010-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* functions.c (help_weeknum): state the default for the method
 	(help_weekday): ditto
 
diff --git a/plugins/fn-date/functions.c b/plugins/fn-date/functions.c
index c93e7d0..9018e2a 100644
--- a/plugins/fn-date/functions.c
+++ b/plugins/fn-date/functions.c
@@ -733,7 +733,7 @@ static GnmFuncHelp const help_workday[] = {
         { GNM_FUNC_HELP_ARG, F_("date:date serial value")},
         { GNM_FUNC_HELP_ARG, F_("days:number of days to add")},
         { GNM_FUNC_HELP_ARG, F_("holidays:array of holidays")},
-        { GNM_FUNC_HELP_ARG, F_("weekend:array indicating whether a weekday (S, M, T, W, T, F, S) is on the weekend, defaults to {TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE}.")},
+        { GNM_FUNC_HELP_ARG, F_("weekend:array indicating whether a weekday (S, M, T, W, T, F, S) is on the weekend, defaults to {TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE}")},
 	{ GNM_FUNC_HELP_DESCRIPTION, F_("WORKDAY adjusts @{date} by @{days} skipping over weekends and @{holidays} in the process.") },
 	{ GNM_FUNC_HELP_NOTE, F_("@{days} may be negative.") },
 	{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible if the last argument is omitted.") },
@@ -949,7 +949,7 @@ static GnmFuncHelp const help_networkdays[] = {
         { GNM_FUNC_HELP_ARG, F_("start_date:starting date serial value")},
         { GNM_FUNC_HELP_ARG, F_("end_date:ending date serial value")},
         { GNM_FUNC_HELP_ARG, F_("holidays:array of holidays")},
-        { GNM_FUNC_HELP_ARG, F_("weekend:array indicating whether a weekday (S, M, T, W, T, F, S) is on the weekend, defaults to {TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE}.")},
+        { GNM_FUNC_HELP_ARG, F_("weekend:array indicating whether a weekday (S, M, T, W, T, F, S) is on the weekend, defaults to {TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE}")},
 	{ GNM_FUNC_HELP_DESCRIPTION, F_("NETWORKDAYS calculates the number of days from @{start_date} to @{end_date} skipping weekends and @{holidays} in the process.") },
 	{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible if the last argument is omitted.") },
 	{ GNM_FUNC_HELP_ODF, F_("This function is OpenFormula compatible.") },
diff --git a/plugins/fn-hebrew-date/ChangeLog b/plugins/fn-hebrew-date/ChangeLog
index 7e9408a..be5cb06 100644
--- a/plugins/fn-hebrew-date/ChangeLog
+++ b/plugins/fn-hebrew-date/ChangeLog
@@ -1,5 +1,12 @@
 2010-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* plugin.xml.in: new functions DATE2HDATE, DATE2HDATE_HEB, and
+	  DATE2JULIAN
+	* functions.c: ditto
+	(gnumeric_date_get_date): new
+
+2010-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* functions.c: update all argument descriptions, defaulting to
 	  the current day. Don 't ignore the return value of hdate_gdate_to_hdate
 
diff --git a/plugins/fn-hebrew-date/functions.c b/plugins/fn-hebrew-date/functions.c
index 3afc874..8b57847 100644
--- a/plugins/fn-hebrew-date/functions.c
+++ b/plugins/fn-hebrew-date/functions.c
@@ -36,6 +36,7 @@
 #include <mathfunc.h>
 #include <workbook.h>
 #include <sheet.h>
+#include <gnm-datetime.h>
 
 #include <math.h>
 
@@ -46,6 +47,8 @@
 
 GNM_PLUGIN_MODULE_HEADER;
 
+#define DATE_CONV(ep)               workbook_date_conv ((ep)->sheet->workbook)
+
 static void
 gnumeric_hdate_get_date (GnmValue const * const *arg, int *year, int *month, int *day)
 {
@@ -64,6 +67,24 @@ gnumeric_hdate_get_date (GnmValue const * const *arg, int *year, int *month, int
 	return;
 }
 
+static GnmValue *
+gnumeric_date_get_date (GnmFuncEvalInfo * ei, GnmValue const * const val, 
+			int *year, int *month, int *day)
+{
+	GDate date;
+
+	if (val == NULL)
+		g_date_set_time_t (&date, time (NULL));
+	else if (!datetime_value_to_g (&date, val, DATE_CONV (ei->pos)))
+		return value_new_error_NUM (ei->pos);
+		
+	*year = g_date_get_year (&date);
+	*month = g_date_get_month (&date);
+	*day = g_date_get_day (&date);
+	
+	return NULL;
+}
+
 /***************************************************************************/
 
 static GnmFuncHelp const help_hdate[] = {
@@ -99,6 +120,42 @@ gnumeric_hdate (GnmFuncEvalInfo * ei, GnmValue const * const *argv)
 
 /***************************************************************************/
 
+
+
+static GnmFuncHelp const help_date2hdate[] = {
+	{ GNM_FUNC_HELP_NAME, F_("DATE2HDATE:Hebrew date") },
+        { GNM_FUNC_HELP_ARG, F_("date:Gregorian date, defaults to today")},
+        { GNM_FUNC_HELP_EXAMPLES, "=DATE2HDATE(DATE(2001,3,30))" },
+        { GNM_FUNC_HELP_EXAMPLES, "=DATE2HDATE()" },
+        { GNM_FUNC_HELP_SEEALSO, "HDATE,DATE2HDATE_HEB"},
+	{ GNM_FUNC_HELP_END }
+};
+
+static GnmValue *
+gnumeric_date2hdate (GnmFuncEvalInfo * ei, GnmValue const * const *argv)
+{
+	int year, month, day;
+	int hyear, hmonth, hday;
+	char *res;
+	GnmValue *val;
+
+	val = gnumeric_date_get_date (ei,argv[0], &year, &month, &day);
+	if (val != NULL)
+		return val;
+
+	if (0 != hdate_gdate_to_hdate (day, month, year, &hday, &hmonth, &hyear))
+		return value_new_error_VALUE (ei->pos);
+
+	res = g_strdup_printf ("%d %s %d",
+			       hday + 1,
+			       hdate_get_hebrew_month_name (hmonth),
+			       hyear);
+
+	return value_new_string_nocopy (res);
+}
+
+/***************************************************************************/
+
 static GnmFuncHelp const help_hdate_heb[] = {
 	{ GNM_FUNC_HELP_NAME, F_("HDATE_HEB:Hebrew date in Hebrew") },
         { GNM_FUNC_HELP_ARG, F_("year:Gregorian year of date, defaults to the current year")},
@@ -134,6 +191,42 @@ gnumeric_hdate_heb (GnmFuncEvalInfo * ei, GnmValue const * const *argv)
 
 /***************************************************************************/
 
+static GnmFuncHelp const help_date2hdate_heb[] = {
+	{ GNM_FUNC_HELP_NAME, F_("DATE2HDATE_HEB:Hebrew date in Hebrew") },
+        { GNM_FUNC_HELP_ARG, F_("date:Gregorian date, defaults to today")},
+        { GNM_FUNC_HELP_EXAMPLES, "=DATE2HDATE_HEB(DATE(2001,3,30))" },
+        { GNM_FUNC_HELP_EXAMPLES, "=DATE2HDATE_HEB()" },
+        { GNM_FUNC_HELP_SEEALSO, "DATE2HDATE,HDATE_HEB"},
+	{ GNM_FUNC_HELP_END }
+};
+
+static GnmValue *
+gnumeric_date2hdate_heb (GnmFuncEvalInfo * ei, GnmValue const * const *argv)
+{
+	int year, month, day;
+	int hyear, hmonth, hday;
+	GString *res;
+	GnmValue *val;
+
+	val = gnumeric_date_get_date (ei,argv[0], &year, &month, &day);
+	if (val != NULL)
+		return val;
+
+	if (0 != hdate_gdate_to_hdate (day, month, year, &hday, &hmonth, &hyear))
+		return value_new_error_VALUE (ei->pos);
+
+	res = g_string_new (NULL);
+	hdate_int_to_hebrew (res, hday + 1);
+	g_string_append_c (res, ' ');
+	g_string_append (res, hdate_get_hebrew_month_name_heb (hmonth));
+	g_string_append_c (res, ' ');
+	hdate_int_to_hebrew (res, hyear);
+
+	return value_new_string_nocopy (g_string_free (res, FALSE));
+}
+
+/***************************************************************************/
+
 static GnmFuncHelp const help_hdate_month[] = {
 	{ GNM_FUNC_HELP_NAME, F_("HDATE_MONTH:Hebrew month of Gregorian date") },
         { GNM_FUNC_HELP_ARG, F_("year:Gregorian year of date, defaults to the current year")},
@@ -241,6 +334,33 @@ gnumeric_hdate_julian (GnmFuncEvalInfo * ei, GnmValue const * const *argv)
 
 /***************************************************************************/
 
+static GnmFuncHelp const help_date2julian[] = {
+	{ GNM_FUNC_HELP_NAME, F_("DATE2JULIAN:Julian day number for given Gregorian date") },
+        { GNM_FUNC_HELP_ARG, F_("date:Gregorian date, defaults to today")},
+        { GNM_FUNC_HELP_EXAMPLES, "=DATE2JULIAN(DATE(2001,3,30))" },
+        { GNM_FUNC_HELP_EXAMPLES, "=DATE2JULIAN()" },
+        { GNM_FUNC_HELP_SEEALSO, "HDATE_JULIAN"},
+	{ GNM_FUNC_HELP_END }
+};
+
+static GnmValue *
+gnumeric_date2julian (GnmFuncEvalInfo * ei, GnmValue const * const *argv)
+{
+	int year, month, day;
+	int julian;
+	GnmValue *val;
+
+	val = gnumeric_date_get_date (ei, argv[0], &year, &month, &day);
+	if (val != NULL)
+		return val;
+	
+	julian = hdate_gdate_to_jd (day, month, year);
+
+	return value_new_int (julian);
+}
+
+/***************************************************************************/
+
 GnmFuncDescriptor const datetime_functions[] = {
 	{"hdate", "|fff", help_hdate,
 	 gnumeric_hdate, NULL, NULL, NULL, NULL,
@@ -272,5 +392,20 @@ GnmFuncDescriptor const datetime_functions[] = {
 	 GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_UNITLESS,
 	 GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC,
 	 GNM_FUNC_TEST_STATUS_NO_TESTSUITE},
+	 {"date2hdate", "|f", help_date2hdate,
+	 gnumeric_date2hdate, NULL, NULL, NULL, NULL,
+	 GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_UNITLESS,
+	 GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC,
+	 GNM_FUNC_TEST_STATUS_NO_TESTSUITE},
+	 {"date2hdate_heb", "|f", help_date2hdate_heb,
+	 gnumeric_date2hdate_heb, NULL, NULL, NULL, NULL,
+	 GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_UNITLESS,
+	 GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC,
+	 GNM_FUNC_TEST_STATUS_NO_TESTSUITE},
+	 {"date2julian", "|f", help_date2julian,
+	 gnumeric_date2julian, NULL, NULL, NULL, NULL,
+	 GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_UNITLESS,
+	 GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC,
+	 GNM_FUNC_TEST_STATUS_NO_TESTSUITE},
 	{NULL}
 };
diff --git a/plugins/fn-hebrew-date/plugin.xml.in b/plugins/fn-hebrew-date/plugin.xml.in
index 48f5d13..259ad1e 100644
--- a/plugins/fn-hebrew-date/plugin.xml.in
+++ b/plugins/fn-hebrew-date/plugin.xml.in
@@ -17,6 +17,9 @@
 				<function name="hdate_day"/>
 				<function name="hdate_year"/>
 				<function name="hdate_julian"/>
+				<function name="date2hdate"/>
+				<function name="date2hdate_heb"/>
+				<function name="date2julian"/>
 			</functions>
 		</service>
 	</services>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]