You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inserting Date values into Spanner date column fails #2097
What about spanner.date() that takes the same constructor as new Date() ? Or even a date?
I imagine that I get a date as an actual JS date somehow, and want to put that into Spanner in a DATE column. In this world I'd have to... call spanner.date(dateformat(mydateval, ...)) which makes me sad.
At the very least I'd like to be able to do spanner.date(mydateval) and have it do the right thing. Can we do that?
It also looks like dates are encoded if sent directly. Does a spanner.date work and a Date not work? If so, we could fix it by changing line 156 to value = new SpannerDate(value).value.
The code linked here leads me to believe that the string representation (or the date representation) will work, but it won't handle the same parameters that new Date does.. but this may be for the best.
In code...
// Copy and paste in the definition (spanner.date is promisified weirdly)>functionSpannerDate(value){
... if(is.undefined(value)){
.....value=newDate();
.....}...
... this.value=newDate(value).toJSON().replace(/T.+/,'');
... }undefined>newSpannerDate('2016-01-01').value'2016-01-01'// But, the you can't use the same arguments, since it only looks at the first:>newSpannerDate(2016,1,1).value'1970-01-01'>newSpannerDate(2016).value'1970-01-01'// But then... it seems that Javascript is pretty stupid with the Date constructor...>newDate(2016,1,1).toJSON()// Months are zero-indexed, but days are not...'2016-02-01T05:00:00.000Z'// And I guess it's crazy to expect JS to say "nah you can't put in garbage crazy dates".// In true JS style, it treats the second argument as "add (val) months" (zero-indexed)// and the third as "add (val-1) days" (one-indexed)>newDate(2016,99,99).toJSON()'2024-07-08T04:00:00.000Z'>newDate(2016,99,98).toJSON()'2024-07-07T04:00:00.000Z'>newSpannerDate(newDate(2016,1,1)).value'2016-02-01'
So: I now retract my request to support the same arguments because new Date is ... certifiably insane.
My new request is that we throw an error when you do spanner.date(year, month, day). Is that doable?
So: I now retract my request to support the same arguments because new Date is ... certifiably insane.
I was considering pointing out to you that the two lines you had in your original post were not equivalent because JavaScript uses zero-indexing for months (why? why? whyyyyyy?) :-)
My new request is that we throw an error when you do spanner.date(year, month, day). Is that doable?
Yes, except what we will actually do is throw an error if you send a Number to year. that is less than or equal to, say, 0 < x <= 9,999. (Anything above that will be treated as a timestamp.) <-- Nevermind, new Date(timestamp) does not do what any normal person would expect, either.
I can also do a thing where if we get three ints, we subtract one from the month and forward them to new Date. That would get you what you originally wanted. I would probably be reticent to it just because of the whole zero-indexed months confusion.
Activity
stephenplusplus commentedon Mar 17, 2017
It is honored as a
TIMESTAMPcurrently. We also havespanner.date('08-08-08')forDATE.jgeewax commentedon Mar 17, 2017
What about
spanner.date()that takes the same constructor asnew Date()? Or even a date?I imagine that I get a date as an actual JS date somehow, and want to put that into Spanner in a
DATEcolumn. In this world I'd have to... callspanner.date(dateformat(mydateval, ...))which makes me sad.At the very least I'd like to be able to do
spanner.date(mydateval)and have it do the right thing. Can we do that?vkedia commentedon Mar 20, 2017
Yeah I agree it would be nice to have a constructor on spanner.Date which takes the individual fields.
lukesneeringer commentedon Mar 21, 2017
According to the documentation and the code,
spanner.date()already coerces a Date properly (in fact, it coerces strings to dates, not vice versa).lukesneeringer commentedon Mar 21, 2017
It also looks like dates are encoded if sent directly. Does a
spanner.datework and aDatenot work? If so, we could fix it by changing line 156 tovalue = new SpannerDate(value).value.jgeewax commentedon Mar 22, 2017
The code linked here leads me to believe that the string representation (or the date representation) will work, but it won't handle the same parameters that
new Datedoes.. but this may be for the best.In code...
So: I now retract my request to support the same arguments because
new Dateis ... certifiably insane.My new request is that we throw an error when you do
spanner.date(year, month, day). Is that doable?lukesneeringer commentedon Mar 22, 2017
I was considering pointing out to you that the two lines you had in your original post were not equivalent because JavaScript uses zero-indexing for months (why? why? whyyyyyy?) :-)
Yes, except what we will actually do is throw an error if you send a
Numbertoyear.that is less than or equal to, say,<-- Nevermind,0 < x <= 9,999. (Anything above that will be treated as a timestamp.)new Date(timestamp)does not do what any normal person would expect, either.I can also do a thing where if we get three ints, we subtract one from the month and forward them to
new Date. That would get you what you originally wanted. I would probably be reticent to it just because of the whole zero-indexed months confusion.Throw TypeError if we get a Number to spanner.date.
chore(main): release 6.6.0 (#2097)
observability: add base for instrumentation + tests (#2097)
chore(main): release 6.6.0 (googleapis#2097)