In Kotlin JS calling getHours on a date gives TypeError: date.getHours is not a function - kotlin-js

Hopefully this is a common issue that someone can help me with ?
I've got a data class that has a kotlin,js.Date on it. If I print out the value of it via console.log I get:
2019-12-29T13:30:00.000+0000
I'm trying to get the hours portion so I do
date.getHours()
and I'm getting "TypeError: date.getHours is not a function" as a runtime error in the browser.
I don't quite understand this; does my date object not contain a date or something ?

You have to first convert it to js Date
new Date('2019-12-29T13:30:00.000+0000').getHours()
and then you can call its functions.

It turned out I was doing an unsafe cast and what I thought was a js date was actually a string :-)

Related

When trying to create a DataFrame getting 'TypeError: 'dict' object is not callable' despite calling a series, not a dict?

I have created a series from an existing data frame using value_counts(), and want to turn the output of this into a new data frame, as below:
yeardata= dataset1['Year'].value_counts()
totals = pd.DataFrame(yeardata)
and I am getting the following error:
TypeError: 'dict' object is not callable
I don't understand this, as nowhere within that code am I trying to call a dict. Using type() for yeardata it confirms that this is a series.
I swear this code was working earlier and I haven't changed anything above it but it's now suddenly kicking out an error
Does anyone know what the issue is?
thanks!
You can also use to_frame():
totals = yeardata.to_frame()
Use
totals = pd.DataFrame.from_dict(yeardata)

Issue with Testcafe: withText is not a function

noob coder here, not pretending to be anything else.
I'm trying to write a selector in Testcafe, and according to the documentation (so far as I have understood it) this should work, however it returns an error:
await t.click(Selector('span').withtext('Pending Applications').find(a.field-link.external-link))
The error it returns is
TypeError: (0 , _exportableLib.Selector)(...).withtext is not a function
Am I doing something wrong?
There is small typo in your code. You have to use 'withText()' instead of 'withtext().
await t.click(Selector('span').withText('Pending Applications').find('a.field-link.external-link'))

React Native Formik - Error at passing Object to HandleChange

I'm trying to save an Object on form.values to work with it later on a Query.
The problem is, even I have used it on another project, this time it gives this error:
Does anyone have some clue about this?
The specific line I'm inputting this is this one:
onChange={form.handleChange('MultipleSelect')({})}
I'm not sure, but I think it is not finding the '_eventOrTextValue' function...
I have tried passing integers, objects, arrays, but the only kind of value it accepts is string...
Oddly I used this same mirrored function on another project the same way...

Velocity template function from string literal

Is it possible to call a function that was created from string literal? For example
${object}.staticPartOfFunctionName${dynamicPartOfFunctionName}()
doesn't return correct value, but instead just prints the object and the function name.
$object.staticFunctionName()
prints correctly, and
$object.staticPartOfFunctionName${dynamicPartOfFunctionName}()
gives warning "Encountered ")"
You don't have to use introspection:
#evaluate("\$object.staticPartOfFunctionName${dynamicPartOfFunctionName}()")
Well, I found one solution myself from Java side:
$object.getClass().getMethod("staticPartOfFunctionName$dynamicPartOfFunctionName").invoke($object))
I don't know if it's any good, so if someone knows how to do it velocity way, lemme know.

Why does this simple string formating now throw exception?

I'm using Authorize.net API and they require card expiration field to be formated as "yyyy-mm". We did that with this simple line of code:
expirationDate = model.Year.ToString("D4") & "-" & model.Month.ToString("D2")
and this absolutelly worked. I still have cards stored in the system that were saved using this method! But today I was testing something completelly unrelated, and wanted to add another card, and bam, this code exploded with this exception:
System.InvalidCastException: 'Conversion from string "D4" to type 'Integer' is not valid.'
Inner exception to that one is:
Input string was not in a correct format.
This just... doesn't make sense to me. Why in the world is it trying to convert format specifier (D4) into an integer? What input string? What in the world changed in two days?
The problem is that your are using a Nullable(Of Integer). This is a different structure that does not support the overloads of the ToString method a normal Integer has.
You can view the overloads of the Nullable structure here.
I suggest you use the GetValueOrDefault() method to get the proper Integer and also apply the value you expect in case the value is Nothing.
If it is impossible that a instance with a Nothing set for the year reaches this method you can simply use the Value property.
I still do not fully understand why you get this strange error message. Maybe you could check out what the actual method that is called is? Pointing at the method should give you that information. It can't be Nullable(Of Integer).ToString
Well, I found a workable solution and something of an answer thanks to #Nitram's comment. The type of Year/Month property has been changed from Integer to Integer?. Obviously, this isn't a very satisfying answer because I still don't understand why the nullable int can't be formatted, and yet the code compiles perfectly. The working solution for me has been using static format method on String as so:
expirationDate = String.Format("{0:D4}-{1:D2}", model.Year, model.Month)
This works fine even with nullable types.