[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: patch for weeknum
From: Sascha Pfau <mrpeacock () gmail ! com>
Date: 2006-12-15 17:21:33
Message-ID: 200612151821.33926.MrPeacock () gmail ! com
[Download RAW message or body]
hello list,
i've implemented the weeknum function. the patch is attached. the description
of the weeknum function isn't complete, because my english ...
please can you tell how to return a parsing error, if there are more than 2
parameters...
greets
Sascha Pfau
["kspread-add-weeknum.patch" (text/x-diff)]
--- ./datetime.xml.org 2006-12-10 11:52:22.000000000 +0100
+++ ./datetime.xml 2006-12-15 17:57:51.000000000 +0100
@@ -595,6 +595,25 @@
</Help>
</Function>
+ <Function>
+ <Name>WEEKNUM</Name>
+ <Type>Int</Type>
+ <Parameter>
+ <Comment>Date</Comment>
+ <Type>String</Type>
+ </Parameter>
+ <Parameter>
+ <Comment>Method (optional)</Comment>
+ <Type>Int</Type>
+ </Parameter>
+ <Help>
+ <Text>The WEEKNUM() function returns number of the week which the date falls \
into.</Text> + <Syntax>WEEKNUM(date; method)</Syntax>
+ <Example>WEEKNUM(A1; 1) returns 11 when A1 is "9th of March 2008". Number of \
the week in the year, with a week beginning on Sunday (11)</Example> + \
<Example>WEEKNUM(A1; 2) returns 10 when A1 is "9th of March 2008". Number of the week \
in the year, with a week beginning on Monday (10)</Example> + </Help>
+ </Function>
+
</Group>
</KSpreadFunctions>
--- ./datetime.cpp.org 2006-12-10 11:52:22.000000000 +0100
+++ ./datetime.cpp 2006-12-15 18:08:15.000000000 +0100
@@ -61,6 +61,7 @@
Value func_timevalue (valVector args, ValueCalc *calc, FuncExtra *);
Value func_today (valVector args, ValueCalc *calc, FuncExtra *);
Value func_weekday (valVector args, ValueCalc *calc, FuncExtra *);
+Value func_weekNum (valVector args, ValueCalc *calc, FuncExtra *);
Value func_weeks (valVector args, ValueCalc *calc, FuncExtra *);
Value func_weeksInYear (valVector args, ValueCalc *calc, FuncExtra *);
Value func_year (valVector args, ValueCalc *calc, FuncExtra *);
@@ -159,6 +160,9 @@
f = new Function ("WEEKDAY", func_weekday);
f->setParamCount (1, 2);
repo->add (f);
+ f = new Function ("WEEKNUM", func_weekNum);
+ f->setParamCount (1, 2);
+ repo->add (f);
f = new Function ("WEEKS", func_weeks);
f->setParamCount (3);
repo->add (f);
@@ -647,3 +651,38 @@
return Value (date.weekNumber());
}
+
+// Function: weekNum
+//
+// method startday name of day
+// default: 1 0 sunday
+// 2 -1 monday
+//
+// weeknum = (startday + 7 + dayOfWeek of New Year + difference in days) / 7
+//
+Value func_weekNum (valVector args, ValueCalc *calc, FuncExtra *)
+{
+ Value v( calc->conv()->asDate (args[0]).asDate( calc->doc() ), calc->doc() );
+ if (v.isError()) return v;
+ QDate date = v.asDate( calc->doc() );
+
+ if (!date.isValid())
+ return Value::errorVALUE();
+
+ int method = 1;
+ if (args.count() > 1)
+ method = calc->conv()->asInteger (args[1]).asInteger();
+
+ if ( method < 1 || method > 2 )
+ return Value::errorVALUE();
+
+ QDate date1 ( date.year(), 1, 1 );
+ int days = date1.daysTo (date);
+
+ int startday=0;
+ if (method == 2)
+ startday=-1;
+
+ //kDebug(36002) << "weeknum = [startday(" << startday << ") + base(7) + New Year(" \
<< date1.dayOfWeek() <<") + days(" << days << ")] / 7 = " << \
(startday+7+date1.dayOfWeek()+days)/7 << endl; + return Value( \
(int)(startday+7+date1.dayOfWeek()+days)/7 ); +}
_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic