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

Add mutation for date operation #4917

Open
boretti opened this issue Jul 31, 2024 · 6 comments
Open

Add mutation for date operation #4917

boretti opened this issue Jul 31, 2024 · 6 comments
Labels
🚀 Feature request New feature request

Comments

@boretti
Copy link
Contributor

boretti commented Jul 31, 2024

Is your feature request related to a problem? Please describe.
It would be interesting to have mutation produced for operation on Date.

Expression like :

aDate.setDate(aDate.getDate()+1)

will produce interesting mutation based on the +1. It would also be interesting to have mutation changing the setDate or getDate operation (as updating month and not the day of month).

Describe the solution you'd like
I propose to add the following mutation (to method-expression-mutator) :

  • getDate to/from getMonth
  • setDate to/from setMonth
  • getHours to/from getMinutes
  • setHours to/from setMinutes

Describe alternatives you've considered

Maybe other method are interesting to be mutated, but I think, a first set to start with is enough

Additional context

I will also create a PR with the proposal and link it with this Feature Request.

@boretti
Copy link
Contributor Author

boretti commented Aug 2, 2024

I think this is a good idea to have all these methods supported. I would also support both the get and the set version of the method.

@nicojs
Copy link
Member

nicojs commented Aug 2, 2024

I'm personally less in favor of getxxx mutations. Could you provide an example where it would be useful and is not covered by a setXxx mutation?

@boretti
Copy link
Contributor Author

boretti commented Aug 3, 2024

I have the following example for get mutation, which are mostly business rules based on the date or the time :

  • In Switzerland, the retirement age will change for the woman, in the next year, with rules like In 2025, the new reference age for woman born in 1961, will be 64 years and 3 months, in 2026, for woman born in 1962, it will be 64 year and 6 month, ...
    You will end up will rule only based on the get :
    if(currentDate.getFullYear() === 2025 && sex === 'F' && birthDate.getFullYear() === 1961) {
      // Retirement age is
    } else ...
    
  • Another rule, an example for Switzerland, is that we must add a pay supplement when people work night or weekend. It may also require rules based on getHours() and getMinutes() to implements this logic.
  • When you need to display date in some language, you may have requirements that, in French, the first day of the month is written "1er" (and in Italian, it may be 1°), but the next day are "only" 2, 3, ... ; Also in Italian, you may have to change how some word are written depending on the number following it.

@nicojs
Copy link
Member

nicojs commented Aug 6, 2024

Thanks for the examples. I these particular examples are already tackled by the equality operator group of mutants, correct?

The problem with adding mutants for all methods is that they often overlap with other mutants that we already have. You probably call getHours() to calculate something or call setHours on another Date. The calculations are already covered by existing mutators. Your PR will cover the setHours.

Can you agree with this?

@boretti
Copy link
Contributor Author

boretti commented Aug 12, 2024

I see your point.

The equality operator should cover these case. I will update the PR according.

boretti added a commit to boretti/stryker-js that referenced this issue Aug 12, 2024
nicojs pushed a commit that referenced this issue Aug 14, 2024
* feat(instrumenter): add expression mutator for Date (#4917)

* feat(instrumenter): add more expression mutator for Date (#4917)

* feat(instrumenter): add expression mutator for Date (#4917)

Remove the get mutator according exchange in the issue #4917
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Feature request New feature request
Projects
None yet
Development

No branches or pull requests

2 participants