• Resolved Stonehenge Creations

    (@duisterdenhaag)


    Hi πŸ™‚

    I have encountered a “small” error in the invoice date. It seems to use the date associated to the UTC and not the WordPress time. Here in The Netherlands (and Western Europe) it is currently UTC+2 (daylight savings time) and we will go back to UTC+1 in October.

    If I (or a visitor through a front-end form) create a new invoice between 00:00 AM and 01:59 AM (local time), Sliced Invoices will use yesterday’s date, even though WordPress is already using the correct date.

    How can I correct this? I am willing to alter the code myself until the next update. πŸ™‚

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support Andrea Whitmer

    (@nutsandboltsmedia)

    Hi Patrick,

    Sorry you’re having trouble! Sliced Invoices uses the WordPress blog time, whatever it is – we don’t specify time anywhere in the code other than to grab whatever WordPress time is set. Do you have any plugins installed with time zone settings of any type?

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    Thank you for the fast reply, Andrea.

    Unfortunately, I think you are mistaken… Sliced Invoices is the only plugin having this problem. P.e. Events Manager uses dates as well and that works fine.

    Also, date is mentioned in the code:
    class-sliced-admin.php, lines 691-713.

    Could you then please tell me in which file the value of the side meta box for the invoice date is called? I will lok into it myself.

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    To empower that… πŸ˜‰
    My date settings are d-m-Y in WordPress, but Sliced Invoiced changes that for the invoice date to Y-m-d.

    The part of code I mentioned seems to be doing that.

    Plugin Support Andrea Whitmer

    (@nutsandboltsmedia)

    Thanks! We are doing some checking and I’ll update you as soon as possible.

    Plugin Support Andrea Whitmer

    (@nutsandboltsmedia)

    The lines you mentioned do refer to the date, but just for formatting – we aren’t actually getting the current time in that section.

    Since you mentioned using a front end form, do you mind to open a ticket via your Sliced Invoices account so we can have a closer look at this issue? The license key from any of your free extensions should allow you to submit the form.

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    I am using Caldera Forms to create the custom post type sliced_invoice, as the Gravity Forms add-on did not get enough data from the form to the invoice for me… So I cannot submit a ticket.

    But still, the same error occurs if I manually create a new invoice from the Admin Dashboard. So the problem is not in the front-end form, but the way SI gets the date. πŸ˜‰

    I strongly feel the error comes from date(). The problem is, I can only test it myself every night in that small window of two hours.

    It might be due to the CMB2 date picker code? I have seen issues on that online.

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    I think I found the error!

    It seems to be caused by get_todays_date_iso8601() in class-sliced-shared.php.

    $today = date_i18n( $format, (int) current_time( 'timestamp', true ) );

    ‘true’ will get the GMT time, while ‘false’ will use the WordPress option, so the offset will be used. See the last line of ‘Description’ in: https://developer.wordpress.org/reference/functions/current_time/
    I have now changed that to ‘false’ and will test it tomorrow night. πŸ˜‰

    Additionally:
    I have changed line 652 in sliced-admin-metaboxes.php to:
    'date_format' =>; get_option( 'date_format' ),

    This will make the invoice date format the same for all dates on the blog. πŸ˜‰

    Plugin Author SlicedInvoices

    (@slicedinvoices)

    Hi Patrick,

    I would caution against making those changes. I’m familiar with the current_time() function and the purpose of the second argument true/false… and I believe “true” is correct here because we always store dates in GMT (or UTC, if you prefer) time. We format dates according to the local time when we need to display them or use them for something, but we always store them in GMT to keep things consistent.

    By changing it to true, you could be effecting other things that depend on it down the line and without doing a lot of testing I couldn’t predict the outcome.

    Also I vaguely remember running into problems with the CMB2 datepickers when formatting them other than Y-m-d, which is why they are that way. However it’s been so long now I don’t remember what the issue was, so I would have to try it again and see what happens. (Who knows, maybe the old problem is gone by now…)

    I’ll do some testing to see if I can reproduce the issue on my side.

    Best,
    David Grant
    Developer of Sliced Invoices

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    Thank you, David,

    I have looked at my database and everything there (5 blogs) is stored with the offset (but naturally as Y-m-d), even Sliced Invoices created and saved within the date offset. So, even though SI “thought” it was created on 2018-04-24 23:30, the database saved it as 2018-04-25 01:30.

    I have also looked at other plugins on my websites. They all seem to save local time (online payments through third parties included). So what exactly do you mean with “we always store in GMT”? Just trying to wrap my head around it. LOL.

    I ran into the CMB2 date issue if other things as well. It seems like you used the current_time() as a workaround for that already. πŸ˜‰

    There are currently no formatting options for displaying dates within SI. So I ended up completely rebuilding the invoice template (front-end) from scratch, because Dutch invoices never use Y-m-d, but always d-m-Y. (From scratch was also my own choice, of course). A little test (reusing the original template with the get_option(date_format) in the code, seems to work just fine.

    So I will test things at my end as well. I know it’s very hard to make an international plugin with dates and finances – especially for the Dutch. We tend to have different rules than most. Currency, postcodes, etc.
    Dutch: € 49,95
    German: 49,95€
    We always have issues with commas and dots in currency: visually we use commas, but technically dots are required, as commas break arrays. This is the main reason why I had to abandon Gravity Forms with Sliced Addon… The form used commas, so Sliced imported € 49,95 as € 49950.00.

    I have tried a lot of plugins for invoicing, and luckily Sliced comes very close! So I am very happy with it. πŸ˜€

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    Hi David,

    I have created several invoices the last few days for which I specifically waited for the two-hour time offset. I have the settings set to ‘false’ and it seems to be solving all my problems πŸ™‚

    Also changing ‘Y-m-d’ to get_option(‘date_format’) doesn’t cause any problems, but does make things more workable for me πŸ˜‰

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    Hi David,

    It still works like a charm here with the altered settings. So I’ll mark this topic as “resolved” and will hope for implementation in an update sometime. πŸ˜‰

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Error in Invoice Date’ is closed to new replies.