dayOfWeek documentation is wrong

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MatLudlam
    Senior Member
    • Aug 2016
    • 288

    dayOfWeek documentation is wrong

    Hi the dayOfWeek function is defined in the documentation here: https://docs.espocrm.com/administrat...etimedayofweek; the doc is wrong.

    The system has Monday as day 0 not Sunday which is what the doc says.

    Just spent ages trying to debug my code, transpires that the code was correct. ;-)

    Thanks.
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Hi Mat,

    Weird. The unit test checks that dayOfWeek('2017-05-07') returns 0. 2017-05-07 was a Sunday. I run unit tests on different environments and they didn't fail.

    https://github.com/espocrm/espocrm/b...Test.php#L1740
    Last edited by yuri; 07-17-2020, 03:10 PM.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • MatLudlam
      Senior Member
      • Aug 2016
      • 288

      #3
      Sorry yuri are you saying that this is an issue or not an issue?

      The code that generated the output below [now deleted] stores the date, a comma and the DOW of that date in a description field.

      The output was
      Code:
      2020-07-18 14:02:50,5
      2020-07-19 14:02:50,6
      2020-07-20 14:02:50,0
      And that shows that the 18th of July (i.e. tomorrow, Saturday) is day 5 and so on.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8440

        #4
        I can't reproduce. It returns 6 for '2020-07-18 14:02:50' for me. Weird.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • yuri
          Member
          • Mar 2014
          • 8440

          #5
          I figured out. It returns a different day of week if a language is set to English (UK). The issue appeared recently, after we utilized Carbon library for date-time formatting.

          I will fix it so that it won't take into account locale settings.
          Last edited by yuri; 07-17-2020, 07:33 PM.
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment

          • MatLudlam
            Senior Member
            • Aug 2016
            • 288

            #6
            Hmmm, great that you can re-produce, but I have concerns that you "fix" it. I spotted that this was an issue, changed my code to deal with it, and created this post. Others may just have changed their code.

            If you "fix" this then my code will stop working as will other peoples. Not sure of the right answer here, but just making a change will cause issues.

            Thanks.

            Comment

            • yuri
              Member
              • Mar 2014
              • 8440

              #7
              Yes. It will cause issues with existing formula for some users. But this worked properly a few months ago. And we should fix it so that it will work as it supposed to and as it worked just recently. It's a bug not a feature.

              You can change dayOfWeek function to datetime\format(DATE_VALUE, 'd') to avoid dayOfWeek usage.
              Last edited by yuri; 07-19-2020, 11:43 AM.
              If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

              Comment

              Working...