Re: 4D JSON Date Bug

2019-02-25 Thread Keisuke Miyako via 4D_Tech
Note: variable names are not supported to start with a number ($4dDate)

the line

OB SET($obj;"apiDate";"2019-02-24")

does not set a date value.
it sets a string that looks like a date to some people.

try something like

$obj:=New object

OB SET($obj;"d1";Current date)
OB SET($obj;"d2";"2019-02-26")
OB SET($obj;"d3";!2019-02-26!)

inspect the object in the debugger,
turn on "display types"

you would see that

d1 looks like "2019-02-26T00:00:00.000Z" in the stringified preview, but 
"19/02/26" or equivalent in the detailed preview and "date" as type.
d2 looks like "2019-02-24" in the stringified and detailed preview and "text" 
as type.
d3 looks exactly like d1

the problem with

OB SET($obj;"apiDate";"2019-02-24")
$apiDate:=OB Get($obj;"apiDate";Is date)

is that you never stored a date or ISO date,
just a -mm-dd string (that has no special meaning in JSON or 4D object),
and the "Is date" coercion forces 4D to interpret it as "ISO date" because it 
is the only kind of date string expected in an object.

if you want to use date string in the -mm-dd (or your local equivalent) you 
need to

$apiDate:=Date(OB Get($obj;"apiDate"))

or

$apiDate:=Date($obj.apiDate)





**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: 4D JSON Date Bug

2019-02-25 Thread Bart Davis via 4D_Tech
Thanks Jeremy,

I turned on the compatibility setting for "Use date type instead of ISO date 
format in objects" and restarted 4D, but still get the same results from the 
code below.  Even if the setting did result in the correct answer, I think that 
4D made a bad decision to make the default behavior change the date for a date 
string that doesn't include time (ie. no T00:00:00).

Bart

> On Feb 24, 2019, at 8:39 PM, Jeremy French  wrote:
> 
> Hi Bart,
> 
> If you store a date in an Object as a string, 4D interprets that date as a 
> UTF date.
> 
> So “2019-02-24” (giving only the date but not time) is interpreted as 
> midnight on the 24th. That is at the stroke of midnight when the 24th day 
> **starts**.
> 
> When you retrieve the value around 6:30 PST on the 24th, 4D is converting to 
> your local time — which is several hours **before** the 24th begins. Hence 
> you see the 23rd.
> 
> If you pass a 4D date, the problem won’t happen. That is replace the string 
> ("2019-02-24”) with a 4D date (#2019-02-24#).
> 
> There’s also a compatibility setting that where you can specify that string 
> dates are to be treated as 4D dates. That is, no time associated with the 
> date. Then your expression:
> 
>> OB SET($obj;"apiDate";"2019-02-24")
> 
> would always return the 24th
> 
> Best regards,
> Jeremy
> 
> 
>> On Feb 24, 2019, at 9:24 PM, Bart Davis via 4D_Tech <4d_tech@lists.4d.com> 
>> wrote:
>> 
>> If you store a 4D date value in an object and retrieve it the value is 
>> correct.  However, if you retrieve a date that is stored in the format 
>> -MM-DD, the date returned is one day less that the date stored.
>> 
>> The code below illustrates the issue.  I have only tested this on Mac OS 
>> using 4D v17.1  (Note:  I tested this at 6:30 pm PST and am not sure if GMT 
>> offset has any effect)
>> 
>> Has anyone else experienced this issue?
>> 
>> Thanks,
>> Bart
>> 
>> C_DATE($4dDate;$apiDate)
>> C_OBJECT($obj)
>> 
>> $obj:=New object
>> $today:=Current date
>> 
>> OB SET($obj;"4Ddate";$today)
>> OB SET($obj;"apiDate";"2019-02-24")
>> 
>> $4dDate:=ob get($obj;"4Ddate";Is date)  // date returned is correct 
>> 2019-02-24
>> $apiDate:=ob get($obj;"apiDate";Is date) // ERROR: date returned is 
>> 2019-02-23
> 

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: 4D JSON Date Bug

2019-02-24 Thread Jeremy French via 4D_Tech
Hi Bart,

If you store a date in an Object as a string, 4D interprets that date as a UTF 
date.

So “2019-02-24” (giving only the date but not time) is interpreted as midnight 
on the 24th. That is at the stroke of midnight when the 24th day **starts**.

When you retrieve the value around 6:30 PST on the 24th, 4D is converting to 
your local time — which is several hours **before** the 24th begins. Hence you 
see the 23rd.

If you pass a 4D date, the problem won’t happen. That is replace the string 
("2019-02-24”) with a 4D date (#2019-02-24#).

There’s also a compatibility setting that where you can specify that string 
dates are to be treated as 4D dates. That is, no time associated with the date. 
Then your expression:

> OB SET($obj;"apiDate";"2019-02-24")


would always return the 24th

Best regards,
Jeremy


> On Feb 24, 2019, at 9:24 PM, Bart Davis via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> If you store a 4D date value in an object and retrieve it the value is 
> correct.  However, if you retrieve a date that is stored in the format 
> -MM-DD, the date returned is one day less that the date stored.
> 
> The code below illustrates the issue.  I have only tested this on Mac OS 
> using 4D v17.1  (Note:  I tested this at 6:30 pm PST and am not sure if GMT 
> offset has any effect)
> 
> Has anyone else experienced this issue?
> 
> Thanks,
> Bart
> 
> C_DATE($4dDate;$apiDate)
> C_OBJECT($obj)
> 
> $obj:=New object
> $today:=Current date
> 
> OB SET($obj;"4Ddate";$today)
> OB SET($obj;"apiDate";"2019-02-24")
> 
> $4dDate:=ob get($obj;"4Ddate";Is date)  // date returned is correct 2019-02-24
> $apiDate:=ob get($obj;"apiDate";Is date) // ERROR: date returned is 2019-02-23

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

4D JSON Date Bug

2019-02-24 Thread Bart Davis via 4D_Tech
I just discovered what I think is a serious bug with 4D reading dates from an 
object.  

If you store a 4D date value in an object and retrieve it the value is correct. 
 However, if you retrieve a date that is stored in the format -MM-DD, the 
date returned is one day less that the date stored.

The code below illustrates the issue.  I have only tested this on Mac OS using 
4D v17.1  (Note:  I tested this at 6:30 pm PST and am not sure if GMT offset 
has any effect)

Has anyone else experienced this issue?

Thanks,
Bart

C_DATE($4dDate;$apiDate)
C_OBJECT($obj)

$obj:=New object
$today:=Current date

OB SET($obj;"4Ddate";$today)
OB SET($obj;"apiDate";"2019-02-24")

$4dDate:=ob get($obj;"4Ddate";Is date)  // date returned is correct 2019-02-24
$apiDate:=ob get($obj;"apiDate";Is date) // ERROR: date returned is 2019-02-23



**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**