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

Fix the documentation for the dateFormats and timeFormats configuration options #956

Merged
merged 20 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ad0d133
Add more unit tests for dateFormats param
sequba Mar 31, 2022
7938d91
Fix typo
sequba Apr 26, 2022
97b951f
Merge branch 'develop' into feature/issue-953
sequba Aug 31, 2022
66e47c7
Improve the API reference for the dateFormats configuration option
sequba Aug 31, 2022
0da6767
Make time-parsing function return the same number regardless of the n…
sequba Aug 31, 2022
20273be
Update the API reference for the timeFormats config parameter
sequba Aug 31, 2022
034f9f1
Add unit tests for dateFormats and timeFormats configuration options
sequba Aug 31, 2022
0ce89a6
Add changelog entry about the rounding issue in the default time-pars…
sequba Sep 1, 2022
b786051
Merge branch 'develop' of github.com:handsontable/hyperformula into f…
sequba Sep 1, 2022
71600ed
Make date-and-time-handling guide more accurate
sequba Sep 1, 2022
d6a883b
Add links to date-and-time-handling guide to the API reference
sequba Sep 1, 2022
f83b5d5
Adjust defaultStringifyDuration function to change of secondsExtended…
sequba Sep 1, 2022
7568464
Add more unit tests for TEXTfunction with duration values
sequba Sep 1, 2022
b6993dc
Add a new unit test for TEXT function with time formats
sequba Sep 4, 2022
8fd38b9
Update changelog - describe the new rounding strategy of the default …
sequba Sep 4, 2022
51e9884
Describe the return values of parseDateTime, stringifyDateTime and st…
sequba Sep 5, 2022
dba4edd
Merge branch 'develop' of github.com:handsontable/hyperformula into f…
sequba Sep 5, 2022
bd4a2d2
Adjust defaultStringifyDateTime to the change of secondsExtendedRegexp
sequba Sep 5, 2022
e389339
Fix 404 in API reference link
sequba Sep 6, 2022
28fde78
Merge branch 'develop' into feature/issue-953
sequba Sep 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed TEXT function rounding issue that caused incorrect conversion of date and time values to strings. [#1043](https://github.com/handsontable/hyperformula/issues/1043)
- Fixed functions SUMIF, SUMIFS, AVERAGEIF, COUNTIF, COUNTIFS to handle complex numeric values correctly. [#951](https://github.com/handsontable/hyperformula/issues/951)
- Fixed the rounding strategy in the default time-parsing function to be independent of the `timeFormats` configuration parameter. Time values will be always rounded to the nearest milisecond (0.001 s). [#953](https://github.com/handsontable/hyperformula/issues/953)

## [2.0.1] - 2022-06-14

Expand Down
285 changes: 131 additions & 154 deletions docs/guide/date-and-time-handling.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# Date and time handling

Date and time formats can be set in the
[configuration options](configuration-options.md).
The formats for the default date and time parsing functions can be set using configuration options:
- [dateFormats](../api/interfaces/configparams.md#dateformats),
- [timeFormats](../api/interfaces/configparams.md#timeformats),
- [nullYear](../api/interfaces/configparams.md#nullyear).

`dateFormats` is a list of formats supported by the parser
inside HyperFormula. The default format is
`['MM/DD/YYYY', 'MM/DD/YY']`. The separator is ignored and it can
be any of the following: '-' (dash), ' ' (empty space),
'/' (slash).

Similar to `dateFormats`, `timeFormats` is a list of time formats
supported by the parser. The default format is
`['hh:mm', 'hh:mm:ss.sss']`. The only accepted separator is ':' (colon).
Comment on lines -6 to -14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is described in the API ref for these configuration options. No need for duplication.


## Example with Chinese

Expand All @@ -24,40 +17,31 @@ const options = {
};
```

## Integration and customization
## Custom functions for handling date and time

HyperFormula offers the possibility to extend the number of supported
date/time formats as well as the behavior of this functionality by exposing
three options:

* `parseDateTime` which allows for providing a function that accepts
- [parseDateTime](../api/interfaces/configparams.md#parsedatetime), which allows to provide a function that accepts
a string representing date/time and parses it into an actual date/time format
* `stringifyDateTime`which allows for providing a function that
- [stringifyDateTime](../api/interfaces/configparams.md#stringifydatetime), which allows to provide a function that
takes the date/time and prints it as a string
* `stringifyDuration` which allows for providing a function that
- [stringifyDuration](../api/interfaces/configparams.md#stringifyduration), which allows to provide a function that
takes time duration and prints it as a string

To extend the number of possible date formats you will need to
configure `parseDateTime` . This functionality is based on callbacks
To extend the number of possible date formats, you will need to
configure `parseDateTime` . This functionality is based on callbacks,
and you can customize the formats by integrating a third-party
library like [Moment.js](https://momentjs.com/), or by writing your
own custom function like this:

```javascript
{
year: number,
month: number,
day: number,
}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a fuller example that is actually a function? This snippet is not clear.

Copy link
Contributor Author

@sequba sequba Sep 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You commented on the removed lines. I also think this code snippet was useless. There is a full example of a custom parseDateTime function in the next section (using Moment.js). Do you think, we need another example?

Copy link
Member

@warpech warpech Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, sorry.

However, the linked explanations in the docs:

are too shallow, in a way that they doesn't explain the return values.

If you could enhance that in the API reference, I think that would be enough.

Copy link
Contributor Author

@sequba sequba Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ok?
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good, but the link to /api/interfaces/globals.html#datetime gives a 404 to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that. It's fixed now.

own custom function that returns a [DateTime](../api/globals.md#datetime) object.

The configuration of date formats and stringify options may have
an impact on how the functions TEXT and VALUE, as well as criterions
(e.g. SUMIF, AVERAGEIF), will behave. For instance, VALUE accepts a string
and returns a number, which means it uses `parseDatetime`. TEXT
works the other way round - it accepts a number and returns a string
The configuration of date formats and stringify options may impact some built-in functions.
For instance, VALUE transforms strings
into numbers, which means it uses `parseDatetime`. TEXT
works the other way round - it accepts a number and returns a string,
so it uses `stringifyDateTime`. Any change here might give you
different results. Criterions do comparisons so they also need to
different results. Criteria-based functions (SUMIF, AVERAGEIF, etc.) perform comparisons, so they also need to
work on strings, dates, etc.

## Moment.js integration
Expand Down Expand Up @@ -106,18 +90,11 @@ your custom format:
const data = [["31st Jan 00", "2nd Jun 01", "=B1-A1"]];
```

And now the operations on dates are possible since HyperFormula
recognizes them as proper dates:
And now, HyperFormula recognizes these values as valid dates and can operate on them.

## Demo

<iframe
src="https://codesandbox.io/embed/github/handsontable/hyperformula-demos/tree/2.0.x/date-time?autoresize=1&fontsize=11&hidenavigation=1&theme=light&view=preview"
style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;"
title="handsontable/hyperformula-demos: date-time"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-autoplay allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
></iframe>
<iframe src="https://codesandbox.io/embed/github/handsontable/hyperformula-demos/tree/2.0.x/date-time?autoresize=1&fontsize=11&hidenavigation=1&theme=light&view=preview" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" title="handsontable/hyperformula-demos: date-time" allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-autoplay allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>

<br><br>

Expand All @@ -126,116 +103,116 @@ recognizes them as proper dates:
Below is a cheat sheet with the most popular date formats in
different countries.

| Country | Language | Format |
| :--- | :--- | :--- |
| Albania | Albanian | yyyy-MM-dd |
| United Arab Emirates | Arabic | dd/MM/yyyy |
| Argentina | Spanish | dd/MM/yyyy |
| Australia | English | d/MM/yyyy |
| Austria | German | dd.MM.yyyy |
| Belgium | French | d/MM/yyyy |
| Belgium | Dutch | d/MM/yyyy |
| Bulgaria | Bulgarian | yyyy-M-d |
| Bahrain | Arabic | dd/MM/yyyy |
| Bosnia and Herzegovina | Bosnian | dd.MM.yyyy. |
| Bosnia and Herzegovina | Serbian | dd.MM.yyyy. |
| Bosnia and Herzegovina | Croatian | dd.MM.yyyy. |
| Belarus | Belarusian | d.M.yyyy |
| Bolivia | Spanish | dd-MM-yyyy |
| Brazil | Portuguese | dd/MM/yyyy |
| Canada | French | yyyy-MM-dd |
| Canada | English | dd/MM/yyyy |
| Switzerland | German | dd.MM.yyyy |
| Switzerland | French | dd.MM.yyyy |
| Switzerland | Italian | dd.MM.yyyy |
| Chile | Spanish | dd-MM-yyyy |
| China | Chinese | yyyy-M-d |
| Colombia | Spanish | d/MM/yyyy |
| Costa Rica | Spanish | dd/MM/yyyy |
| Cyprus | Greek | dd/MM/yyyy |
| Czech Republic | Czech | d.M.yyyy |
| Germany | German | dd.MM.yyyy |
| Denmark | Danish | dd-MM-yyyy |
| Dominican Republic | Spanish | MM/dd/yyyy |
| Algeria | Arabic | dd/MM/yyyy |
| Ecuador | Spanish | dd/MM/yyyy |
| Egypt | Arabic | dd/MM/yyyy |
| Spain | Spanish | d/MM/yyyy |
| Spain | Catalan | dd/MM/yyyy |
| Estonia | Estonian | d.MM.yyyy |
| Finland | Finnish | d.M.yyyy |
| France | French | dd/MM/yyyy |
| United Kingdom | English | dd/MM/yyyy |
| Greece | Greek | d/M/yyyy |
| Guatemala | Spanish | d/MM/yyyy |
| Hong Kong | Chinese | yyyy年M月d日 |
| Honduras | Spanish | MM-dd-yyyy |
| Croatia | Croatian | dd.MM.yyyy. |
| Hungary | Hungarian | yyyy.MM.dd. |
| Indonesia | Indonesian | dd/MM/yyyy |
| India | Hindi | ३/६/१२ |
| India | English | d/M/yyyy |
| Ireland | Irish | dd/MM/yyyy |
| Ireland | English | dd/MM/yyyy |
| Iraq | Arabic | dd/MM/yyyy |
| Iceland | Icelandic | d.M.yyyy |
| Israel | Hebrew | dd/MM/yyyy |
| Italy | Italian | dd/MM/yyyy |
| Jordan | Arabic | dd/MM/yyyy |
| Japan | Japanese | yyyy/MM/dd |
| Japan | Japanese | H24.MM.dd |
| South Korea | Korean | yyyy. M. d |
| Kuwait | Arabic | dd/MM/yyyy |
| Lebanon | Arabic | dd/MM/yyyy |
| Libya | Arabic | dd/MM/yyyy |
| Lithuania | Lithuanian | yyyy.M.d |
| Luxembourg | French | dd/MM/yyyy |
| Luxembourg | German | dd.MM.yyyy |
| Latvia | Latvian | yyyy.d.M |
| Morocco | Arabic | dd/MM/yyyy |
| Mexico | Spanish | d/MM/yyyy |
| Macedonia | Macedonian | d.M.yyyy |
| Malta | English | dd/MM/yyyy |
| Malta | Maltese | dd/MM/yyyy |
| Montenegro | Serbian | d.M.yyyy. |
| Malaysia | Malay | dd/MM/yyyy |
| Nicaragua | Spanish | MM-dd-yyyy |
| Netherlands | Dutch | d-M-yyyy |
| Norway | Norwegian | dd.MM.yyyy |
| Norway | Norwegian | dd.MM.yyyy |
| New Zealand | English | d/MM/yyyy |
| Oman | Arabic | dd/MM/yyyy |
| Panama | Spanish | MM/dd/yyyy |
| Peru | Spanish | dd/MM/yyyy |
| Philippines | English | M/d/yyyy |
| Poland | Polish | dd.MM.yyyy |
| Puerto Rico | Spanish | MM-dd-yyyy |
| Portugal | Portuguese | dd-MM-yyyy |
| Paraguay | Spanish | dd/MM/yyyy |
| Qatar | Arabic | dd/MM/yyyy |
| Romania | Romanian | dd.MM.yyyy |
| Russia | Russian | dd.MM.yyyy |
| Saudi Arabia | Arabic | dd/MM/yyyy |
| Serbia and Montenegro | Serbian | d.M.yyyy. |
| Sudan | Arabic | dd/MM/yyyy |
| Singapore | Chinese | dd/MM/yyyy |
| Singapore | English | M/d/yyyy |
| El Salvador | Spanish | MM-dd-yyyy |
| Serbia | Serbian | d.M.yyyy. |
| Slovakia | Slovak | d.M.yyyy |
| Slovenia | Slovenian | d.M.yyyy |
| Sweden | Swedish | yyyy-MM-dd |
| Syria | Arabic | dd/MM/yyyy |
| Thailand | Thai | d/M/2555 |
| Thailand | Thai | ๓/๖/๒๕๕๕ |
| Tunisia | Arabic | dd/MM/yyyy |
| Turkey | Turkish | dd.MM.yyyy |
| Taiwan | Chinese | yyyy/M/d |
| Ukraine | Ukrainian | dd.MM.yyyy |
| Uruguay | Spanish | dd/MM/yyyy |
| United States | English | M/d/yyyy |
| United States | Spanish | M/d/yyyy |
| Venezuela | Spanish | dd/MM/yyyy |
| Vietnam | Vietnamese | dd/MM/yyyy |
| Yemen | Arabic | dd/MM/yyyy |
| South Africa | English | yyyy/MM/dd |
| Country | Language | Format |
|:-----------------------|:-----------|:------------|
| Albania | Albanian | yyyy-MM-dd |
| United Arab Emirates | Arabic | dd/MM/yyyy |
| Argentina | Spanish | dd/MM/yyyy |
| Australia | English | d/MM/yyyy |
| Austria | German | dd.MM.yyyy |
| Belgium | French | d/MM/yyyy |
| Belgium | Dutch | d/MM/yyyy |
| Bulgaria | Bulgarian | yyyy-M-d |
| Bahrain | Arabic | dd/MM/yyyy |
| Bosnia and Herzegovina | Bosnian | dd.MM.yyyy. |
| Bosnia and Herzegovina | Serbian | dd.MM.yyyy. |
| Bosnia and Herzegovina | Croatian | dd.MM.yyyy. |
| Belarus | Belarusian | d.M.yyyy |
| Bolivia | Spanish | dd-MM-yyyy |
| Brazil | Portuguese | dd/MM/yyyy |
| Canada | French | yyyy-MM-dd |
| Canada | English | dd/MM/yyyy |
| Switzerland | German | dd.MM.yyyy |
| Switzerland | French | dd.MM.yyyy |
| Switzerland | Italian | dd.MM.yyyy |
| Chile | Spanish | dd-MM-yyyy |
| China | Chinese | yyyy-M-d |
| Colombia | Spanish | d/MM/yyyy |
| Costa Rica | Spanish | dd/MM/yyyy |
| Cyprus | Greek | dd/MM/yyyy |
| Czech Republic | Czech | d.M.yyyy |
| Germany | German | dd.MM.yyyy |
| Denmark | Danish | dd-MM-yyyy |
| Dominican Republic | Spanish | MM/dd/yyyy |
| Algeria | Arabic | dd/MM/yyyy |
| Ecuador | Spanish | dd/MM/yyyy |
| Egypt | Arabic | dd/MM/yyyy |
| Spain | Spanish | d/MM/yyyy |
| Spain | Catalan | dd/MM/yyyy |
| Estonia | Estonian | d.MM.yyyy |
| Finland | Finnish | d.M.yyyy |
| France | French | dd/MM/yyyy |
| United Kingdom | English | dd/MM/yyyy |
| Greece | Greek | d/M/yyyy |
| Guatemala | Spanish | d/MM/yyyy |
| Hong Kong | Chinese | yyyy年M月d日 |
| Honduras | Spanish | MM-dd-yyyy |
| Croatia | Croatian | dd.MM.yyyy. |
| Hungary | Hungarian | yyyy.MM.dd. |
| Indonesia | Indonesian | dd/MM/yyyy |
| India | Hindi | ३/६/१२ |
| India | English | d/M/yyyy |
| Ireland | Irish | dd/MM/yyyy |
| Ireland | English | dd/MM/yyyy |
| Iraq | Arabic | dd/MM/yyyy |
| Iceland | Icelandic | d.M.yyyy |
| Israel | Hebrew | dd/MM/yyyy |
| Italy | Italian | dd/MM/yyyy |
| Jordan | Arabic | dd/MM/yyyy |
| Japan | Japanese | yyyy/MM/dd |
| Japan | Japanese | H24.MM.dd |
| South Korea | Korean | yyyy. M. d |
| Kuwait | Arabic | dd/MM/yyyy |
| Lebanon | Arabic | dd/MM/yyyy |
| Libya | Arabic | dd/MM/yyyy |
| Lithuania | Lithuanian | yyyy.M.d |
| Luxembourg | French | dd/MM/yyyy |
| Luxembourg | German | dd.MM.yyyy |
| Latvia | Latvian | yyyy.d.M |
| Morocco | Arabic | dd/MM/yyyy |
| Mexico | Spanish | d/MM/yyyy |
| Macedonia | Macedonian | d.M.yyyy |
| Malta | English | dd/MM/yyyy |
| Malta | Maltese | dd/MM/yyyy |
| Montenegro | Serbian | d.M.yyyy. |
| Malaysia | Malay | dd/MM/yyyy |
| Nicaragua | Spanish | MM-dd-yyyy |
| Netherlands | Dutch | d-M-yyyy |
| Norway | Norwegian | dd.MM.yyyy |
| Norway | Norwegian | dd.MM.yyyy |
| New Zealand | English | d/MM/yyyy |
| Oman | Arabic | dd/MM/yyyy |
| Panama | Spanish | MM/dd/yyyy |
| Peru | Spanish | dd/MM/yyyy |
| Philippines | English | M/d/yyyy |
| Poland | Polish | dd.MM.yyyy |
| Puerto Rico | Spanish | MM-dd-yyyy |
| Portugal | Portuguese | dd-MM-yyyy |
| Paraguay | Spanish | dd/MM/yyyy |
| Qatar | Arabic | dd/MM/yyyy |
| Romania | Romanian | dd.MM.yyyy |
| Russia | Russian | dd.MM.yyyy |
| Saudi Arabia | Arabic | dd/MM/yyyy |
| Serbia and Montenegro | Serbian | d.M.yyyy. |
| Sudan | Arabic | dd/MM/yyyy |
| Singapore | Chinese | dd/MM/yyyy |
| Singapore | English | M/d/yyyy |
| El Salvador | Spanish | MM-dd-yyyy |
| Serbia | Serbian | d.M.yyyy. |
| Slovakia | Slovak | d.M.yyyy |
| Slovenia | Slovenian | d.M.yyyy |
| Sweden | Swedish | yyyy-MM-dd |
| Syria | Arabic | dd/MM/yyyy |
| Thailand | Thai | d/M/2555 |
| Thailand | Thai | ๓/๖/๒๕๕๕ |
| Tunisia | Arabic | dd/MM/yyyy |
| Turkey | Turkish | dd.MM.yyyy |
| Taiwan | Chinese | yyyy/M/d |
| Ukraine | Ukrainian | dd.MM.yyyy |
| Uruguay | Spanish | dd/MM/yyyy |
| United States | English | M/d/yyyy |
| United States | Spanish | M/d/yyyy |
| Venezuela | Spanish | dd/MM/yyyy |
| Vietnam | Vietnamese | dd/MM/yyyy |
| Yemen | Arabic | dd/MM/yyyy |
| South Africa | English | yyyy/MM/dd |
Loading