Changeset View
Changeset View
Standalone View
Standalone View
sheets/functions/datetime.cpp
Show First 20 Lines • Show All 240 Lines • ▼ Show 20 Line(s) | |||||
241 | Value func_eomonth(valVector args, ValueCalc *calc, FuncExtra *) | 241 | Value func_eomonth(valVector args, ValueCalc *calc, FuncExtra *) | ||
242 | { | 242 | { | ||
243 | // add months to date using EDATE | 243 | // add months to date using EDATE | ||
244 | Value modDate = func_edate(args, calc, 0); | 244 | Value modDate = func_edate(args, calc, 0); | ||
245 | if (modDate.isError()) return modDate; | 245 | if (modDate.isError()) return modDate; | ||
246 | 246 | | |||
247 | // modDate is currently in Date format | 247 | // modDate is currently in Date format | ||
248 | QDate date = modDate.asDate(calc->settings()); | 248 | QDate date = modDate.asDate(calc->settings()); | ||
249 | date.setYMD(date.year(), date.month(), date.daysInMonth()); | 249 | date.setDate(date.year(), date.month(), date.daysInMonth()); | ||
250 | 250 | | |||
251 | return Value(date, calc->settings()); | 251 | return Value(date, calc->settings()); | ||
252 | } | 252 | } | ||
253 | 253 | | |||
254 | // internal helper function | 254 | // internal helper function | ||
255 | static int func_days360_helper(const QDate& _date1, const QDate& _date2, bool european) | 255 | static int func_days360_helper(const QDate& _date1, const QDate& _date2, bool european) | ||
256 | { | 256 | { | ||
257 | int day1, day2; | 257 | int day1, day2; | ||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Line(s) | 432 | { | |||
449 | } | 449 | } | ||
450 | 450 | | |||
451 | // type is non-zero now | 451 | // type is non-zero now | ||
452 | // the number of full years in between, starting on 1/1/XXXX | 452 | // the number of full years in between, starting on 1/1/XXXX | ||
453 | if (date1.year() == date2.year()) | 453 | if (date1.year() == date2.year()) | ||
454 | return Value(0); | 454 | return Value(0); | ||
455 | 455 | | |||
456 | if ((date1.month() != 1) || (date1.day() != 1)) | 456 | if ((date1.month() != 1) || (date1.day() != 1)) | ||
457 | date1.setYMD(date1.year() + 1, 1, 1); | 457 | date1.setDate(date1.year() + 1, 1, 1); | ||
458 | date2.setYMD(date2.year(), 1, 1); | 458 | date2.setDate(date2.year(), 1, 1); | ||
459 | 459 | | |||
460 | return Value(date2.year() - date1.year()); | 460 | return Value(date2.year() - date1.year()); | ||
461 | } | 461 | } | ||
462 | 462 | | |||
463 | // Function: MONTHS | 463 | // Function: MONTHS | ||
464 | Value func_months(valVector args, ValueCalc *calc, FuncExtra *) | 464 | Value func_months(valVector args, ValueCalc *calc, FuncExtra *) | ||
465 | { | 465 | { | ||
466 | QDate date1 = calc->conv()->asDate(args[0]).asDate(calc->settings()); | 466 | QDate date1 = calc->conv()->asDate(args[0]).asDate(calc->settings()); | ||
Show All 11 Lines | 477 | if (date2.day() != date2.daysInMonth()) | |||
478 | --months; | 478 | --months; | ||
479 | 479 | | |||
480 | return Value(months); | 480 | return Value(months); | ||
481 | } | 481 | } | ||
482 | 482 | | |||
483 | // type is now non-zero | 483 | // type is now non-zero | ||
484 | // the number of full months in between, starting on 1/XX/XXXX | 484 | // the number of full months in between, starting on 1/XX/XXXX | ||
485 | if (date1.month() == 12) | 485 | if (date1.month() == 12) | ||
486 | date1.setYMD(date1.year() + 1, 1, 1); | 486 | date1.setDate(date1.year() + 1, 1, 1); | ||
487 | else | 487 | else | ||
488 | date1.setYMD(date1.year(), date1.month() + 1, 1); | 488 | date1.setDate(date1.year(), date1.month() + 1, 1); | ||
489 | date2.setYMD(date2.year(), date2.month(), 1); | 489 | date2.setDate(date2.year(), date2.month(), 1); | ||
490 | 490 | | |||
491 | int months = (date2.year() - date1.year()) * 12; | 491 | int months = (date2.year() - date1.year()) * 12; | ||
492 | months += date2.month() - date1.month(); | 492 | months += date2.month() - date1.month(); | ||
493 | 493 | | |||
494 | return Value(months); | 494 | return Value(months); | ||
495 | } | 495 | } | ||
496 | 496 | | |||
497 | // Function: WEEKS | 497 | // Function: WEEKS | ||
▲ Show 20 Lines • Show All 646 Lines • Show Last 20 Lines |