Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EOMONTH() and EDATE() Functions should round date value before evaluation #3436

Closed
1 of 8 tasks
MarkBaker opened this issue Mar 6, 2023 · 0 comments
Closed
1 of 8 tasks

Comments

@MarkBaker
Copy link
Member

MarkBaker commented Mar 6, 2023

This is:

- [X] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

The Excel EOMONTH() and EDATE() functions should always return a float with the date, but with the time truncated to 0.

e.g.

EOMONTH(22269.75, 3) should result in float 22371.0
EDATE(22269.75, 2) should result in float 22331.0

What is the current behavior?

If the dateValue argument to EOMONTH() includes a time, then the result also includes that time.

EOMONTH(22269.75, 3) results in float 22371.75
EDATE(22269.75, 2) results in float 22331.75

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Month;

$dateValue = 22269.75;
$adjustment = 3;
$result = Month::lastDay($dateValue, $adjustment);
var_dump($result); // Should be (float) 22371.0 but is (float) 22371.75

$dateValue = 22269.75;
$adjustment = 2;
$result = Month::adjust($dateValue, $adjustment);
var_dump($result); // Should be (float) 22331.0 but is (float) 22331.75

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

N/A

Which versions of PhpSpreadsheet and PHP are affected?

All

@MarkBaker MarkBaker self-assigned this Mar 6, 2023
@MarkBaker MarkBaker changed the title EOMONTH should round date value before evaluation EOMONTH() Function implementation should round date value before evaluation Mar 6, 2023
@MarkBaker MarkBaker changed the title EOMONTH() Function implementation should round date value before evaluation EOMONTH() and EDATE() Functions should round date value before evaluation Mar 6, 2023
MarkBaker added a commit that referenced this issue Mar 6, 2023
MarkBaker added a commit that referenced this issue Mar 6, 2023
MarkBaker added a commit that referenced this issue Mar 6, 2023
…ding-to-Date

Fix for Issue #3436 - Result from Excel's EDATE() and EOMONTH() should always be rounded to 0 decimal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant