← Back to team overview

openerp-expert-framework team mailing list archive

Re: [Bug 925361] [NEW] [6.1] date values that are initialized as 'defaults' may appear as "off by one day" in some countries depending on the time

 

I fully agree with the concept that dates are timezone agnostic, and thus
they should be treated as a special case.
In the example given it is clear the current initialization code is not
storing HH:MM:SS in the database field. Is not possible to use that fact as
an indicator we are taking about a timezone agnostic date, a treated
accordingly on GTK and WEB UI?

The problem is affecting every place in the system where you are recording
a date. Thus, and as an example here in Argentina, depending on the time of
the day, you set a date and magically is converted to the previous day!
Let me say that this problem is a showstopper for any implementation. It
should be treated as a critical problem, that should be solved before
publishing the RC as an official version

Please, consider a reevaluation of the priority

El 2 de febrero de 2012 09:08, Launchpad Bug Tracker <
925361@xxxxxxxxxxxxxxxxxx> escribió:

> You have been subscribed to a public bug by Olivier Dony (OpenERP)
> (odo-openerp):
>
> This issue was initially discussed on bug 918257. It always existed, but
> was less apparent when addons and framework code were using a timezone
> that was closer to the user's timezone.
>
> As of 6.1 all addons and framework code is supposed to work exclusively
> with UTC datetime values (as discussed on comment #4 of bug 918257), and
> this means the problem will occur more often.
>
> Basically, our main issue is that pure date value (without time) can
> never be converted to different timezones, because depending on the time
> they were recorded, the date may still be yesterday in some parts of the
> world, or already tomorrow. Therefore OpenERP clients (Web & GTK) cannot
> (and should not) perform date conversions when displaying pure date
> fields.
>
> Let me try to explain...
>
> For datetime values, the conversion to the local timezone is easy to do.
> Let's say addons code uses the current time to set the value for a datetime
> field in a new record: 2012-02-02 08:56:00 AM (UTC+00:00).
> The value is converted when it is displayed by the client and will
> unambiguously be 2012-02-02 09:56:00 PM in Auckland where the timezone
> offset is +13:00 at that time.
>
> However when addons code works with dates (without time) to initialize a
> new record, this is what is stored in the database: 2012-02-02 (UTC+00:00).
> When that value is displayed to the user, no conversion of timezone can
> occur because the client has no idea at what time the date was in fact
> recorded!
> 2012-02-02 is correct for an Auckland-based user if the date is recorded
> before 11:00 AM UTC, but if recorded at 1:00PM it should be 2012-02-03,
> because Auckland has just passed midnight already. Web/GTK client cannot
> perform this conversion at all, and must display pure dates as stored in
> the database.
>
> Now, I see a few reasonable options to fix this:
>
> 1. We could convert most date fields to be truly datetime fields in the
> database, and simply set the "display widget" to be a date widget, e.g.
>      <field name="order_date" widget="date"/>
> The field would behave like it does currently, except that the client
> would have enough information to properly display the local date, as it
> would know at what time the date was recorded.
>
> 2. Alternatively we could provide a helper function in the framework to
> easily let addons code grab the current date value *as the client would see
> it*. Instead of initializing default values as we do now, i.e.:
>  _defaults = {
>   # Following gives 2012-02-02 even at 1:00 PM UTC
>   'order_date': lambda *a: time.strftime('%Y-%m-%d')
>  }
> we would therefore do it using the user's timezone provided in the
> context, i.e something like this:
>  _defaults = {
>   # For users in Auckland the following would give 2012-02-02 until
>   # 11:00 AM UTC, and properly return 2012-02-03 afterwards
>   'order_date': lambda cr,uid,ctx:self._current_user_date(cr,uid,ctx)
>  }
>
> I tend to favor the second option, which seems simpler and cleaner to me.
> That would basically mean we break the rule of using only UTC date and time
> values in addons, and consider that pure date values are timezone agnostic
> (which is really the case: a date without a time cannot be properly
> converted to another timezone, ever), or more exactly, that they are only
> valid in the timezone of the user who created that record.
> Date computation would continue to work fine: adding/subtracting days
> would works as expected.
>
> The main limitation with option 2 is that dates cannot would not be
> displayed differently depending on the user's timezone. For distributed
> teams, an invoice created by a user in Auckland on '2012-02-03' would
> appear to be created 'tomorrow' for her colleague in New York where the
> date is still '2012-02-02'. I think this is fine and actually expected,
> we don't want the invoice to be 'floating' between one day and the next.
>
> Any opinions on this?
>
> ** Affects: openobject-server
>     Importance: Medium
>     Assignee: OpenERP's Framework R&D (openerp-dev-framework)
>         Status: Confirmed
>
> --
> [6.1] date values that are initialized as 'defaults' may appear as "off by
> one day" in some countries depending on the time
> https://bugs.launchpad.net/bugs/925361
> You received this bug notification because you are a member of OpenERP
> Framework Experts, which is subscribed to the bug report.
>


--

Gustavo Adrian Marino

Mobile: +54 911 5498 2515

Email: gamarino@xxxxxxxxx

Skype: gustavo.adrian.marino

-- 
You received this bug notification because you are a member of OpenERP
Framework Experts, which is subscribed to the bug report.
https://bugs.launchpad.net/bugs/925361

Title:
  [6.1] date values that are initialized as 'defaults' may appear as
  "off by one day" in some countries depending on the time

Status in OpenERP Server:
  Confirmed

Bug description:
  This issue was initially discussed on bug 918257. It always existed,
  but was less apparent when addons and framework code were using a
  timezone that was closer to the user's timezone.

  As of 6.1 all addons and framework code is supposed to work
  exclusively with UTC datetime values (as discussed on comment #4 of
  bug 918257), and this means the problem will occur more often.

  Basically, our main issue is that pure date value (without time) can
  never be converted to different timezones, because depending on the
  time they were recorded, the date may still be yesterday in some parts
  of the world, or already tomorrow. Therefore OpenERP clients (Web &
  GTK) cannot (and should not) perform date conversions when displaying
  pure date fields.

  Let me try to explain...

  For datetime values, the conversion to the local timezone is easy to do. Let's say addons code uses the current time to set the value for a datetime field in a new record: 2012-02-02 08:56:00 AM (UTC+00:00).
  The value is converted when it is displayed by the client and will unambiguously be 2012-02-02 09:56:00 PM in Auckland where the timezone offset is +13:00 at that time.

  However when addons code works with dates (without time) to initialize a new record, this is what is stored in the database: 2012-02-02 (UTC+00:00). When that value is displayed to the user, no conversion of timezone can occur because the client has no idea at what time the date was in fact recorded!
  2012-02-02 is correct for an Auckland-based user if the date is recorded before 11:00 AM UTC, but if recorded at 1:00PM it should be 2012-02-03, because Auckland has just passed midnight already. Web/GTK client cannot perform this conversion at all, and must display pure dates as stored in the database.

  Now, I see a few reasonable options to fix this:

  1. We could convert most date fields to be truly datetime fields in the database, and simply set the "display widget" to be a date widget, e.g. 
        <field name="order_date" widget="date"/>
  The field would behave like it does currently, except that the client would have enough information to properly display the local date, as it would know at what time the date was recorded. 

  2. Alternatively we could provide a helper function in the framework to easily let addons code grab the current date value *as the client would see it*. Instead of initializing default values as we do now, i.e.:
   _defaults = {
     # Following gives 2012-02-02 even at 1:00 PM UTC
     'order_date': lambda *a: time.strftime('%Y-%m-%d') 
   }
  we would therefore do it using the user's timezone provided in the context, i.e something like this:
   _defaults = {
     # For users in Auckland the following would give 2012-02-02 until
     # 11:00 AM UTC, and properly return 2012-02-03 afterwards
     'order_date': lambda cr,uid,ctx:self._current_user_date(cr,uid,ctx)
   }

  I tend to favor the second option, which seems simpler and cleaner to me. That would basically mean we break the rule of using only UTC date and time values in addons, and consider that pure date values are timezone agnostic (which is really the case: a date without a time cannot be properly converted to another timezone, ever), or more exactly, that they are only valid in the timezone of the user who created that record.
  Date computation would continue to work fine: adding/subtracting days would works as expected.

  The main limitation with option 2 is that dates cannot would not be
  displayed differently depending on the user's timezone. For
  distributed teams, an invoice created by a user in Auckland on
  '2012-02-03' would appear to be created 'tomorrow' for her colleague
  in New York where the date is still '2012-02-02'. I think this is fine
  and actually expected, we don't want the invoice to be 'floating'
  between one day and the next.

  Any opinions on this?

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/925361/+subscriptions


Follow ups