Sequelize / Postgres. Date Array Input Being Read as Text Array - postgresql

I'm trying to seed my database, and one of my model's attributes is of type Date Array(timestamp with time zone). I end up getting this error:
column "myDate" is of type timestamp with time zone[] but expression is of type text[]
It works fine with a date type, but for some reason, only the Date Array is being interpreted as a text array.
I'm seeding the "myDate" field with something like this:
myDate: [new Date(), new Date()]
Am I missing something?

Here's what worked for me:
myDate: Sequelize.literal(`ARRAY['2004-10-19 10:23:54+02']::timestamp with time zone[]`)
Which is a slight variation on this issue:
https://github.com/sequelize/sequelize/issues/11541
(note the differenece in syntax between my answer and the one in the github issue. The latter didn't work for me.)

Or a more simpler form
myDate: '{2004-10-19 10:23:54+02}'
please note the curly brases are inside the quotes.
you could add even more values ex.
myDate: '{2004-10-19 10:23:54+02, 2010-13-19 10:23:54+02}'
Hope this helps.

Related

Unable to filter after Date in Realm swift

I'm trying to apply a filter on realm which includes a Date but with no luck.
I've found out that Date object cannot be passed because the %# format expects a Foundation object as argument, so I've applied a cast to NSDate.
let newDate = Date()
realm.objects(E.self)
.filter(String(format: "%# <= %#", key, newDate as NSDate)).first
The issue that appears is "Unable to parse the format string timestamp==2020-03-20 08:21:00 +0000"
key is the name of the field, which in this case it is "timestamp" and on the model it has the type Date.
Any input is appreciated.
Thanks
You should use:
.filter("\(key) <= %#", newDate as NSDate)
This is calling the overload of Realm's filter method that accepts a format and arguments.
String(format:) is not the right thing to use here, as that just does general string formatting. But here, you want the date to be formatted according to the rules of NSPredicate formats. On the other hand, the key can just be interpolated into the string because the name of the table column doesn't need a special format.
If key comes from a UITextField or something like that, then you might need to beware of injection attacks as well, and validate and/or escape the key properly beforehand.

Get a DateTime with an specific pattern with nscala-time

I am trying to get this pattern 'dd-MM-yyyy' with a variable of type DateTime
#{DateTimeFormat.forPattern("dd-MM-YYYY").parseDateTime(user.birthday.toString)}
But I am getting this error
java.lang.IllegalArgumentException: Invalid format: "2015-12-10T00:00:00.000Z" is malformed at "15-12-10T00:00:00.000Z"
Is there a way to do this with nscala-time?
makes a difference if I am using UTC?
UPDATE
For the moment I am casting to Date and doing this
#{Dates.format(user.birthday.toDate, "dd-MM-YYYY")}
But maybe is a better way without casting
thank you
So, if I understood your question correctly, you are trying to achieve the following:
Parse date from a string using a date format
Print/Display the date in another format.
Try the below:
#{Dates.format(DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parseDateTime(user.birthday.toString), "dd-MM-YYYY")}

momentjs: Get invalid date when trying to get current date with moment()

Hi Im using firefox and CoffeeScript in an app, I want to get current date with momentjs using default method moment() however when I debug the code I seeinvalid Date, it is very weird, this is my code:
questionStarts =
started_at: moment()
running: true
Then later in my code I create another object and add the property
answer = {}
answer.started_at = questionStarts.started_at
But when I check answer.started_at I get back Invalid date any idea?
Moment has an alternate constructor for strange dates. Since I can't see the value of answer.started_at in your code, I can only guess about how to solve your problem.
Consider for example some strange date format like 08.16.2015 00:00:00. Trying to construct a moment object from it will give the same error you have, Invalid date. That's what happens if you tried constructing my example like this:
//this doesn't work, throws Invalid date message
var ex = moment('08.16.2015 00:00:00');
So, to fix my problem, I give another constructor that informs Moment of the strange date format.
//this does work, however
var ex = moment('08.16.2015 00:00:00', 'MM.DD.YYYY hh:mm:ss');
Now, I can use ex as a typical moment object taking advantage of moment's other methods such as format() diff() and isBetween().

Talend Context variable

I am a newbie Talend developer, need a help with context variables. I searched here if there is a solution for similar approach, didnt find it.
In my query I have to use this date range function:
Date BETWEEN to_char((add_months(TRUNC(SYSDATE,'MM'),-2)),'YYYYMMDD')
AND to_char(LAST_DAY(TRUNC(SYSDATE,'MM')),'YYYYMMDD')
We need to use context variable to take advantage to run different date range during runtime. Above function, I replaced in the query with (date between ="+context.daterange+") and trying to plug these functions to Context - value as tree as below:
to_char((add_months(TRUNC(SYSDATE,'MM'),-5)),'YYYYMMDD')'AND'to_char(LAST_DAY(TRUNC(SYSDATE,'MM')),'YYYYMMDD'), I get below error:
java.sql.SQLException: ORA-00905: missing keyword
If I use hard coded value on "Value as tree" context as below then works
"'20150301'and'20150831'"
Trying to replace this with the function. How can I combine that function with AND.
My tJavacode has
context.DATE = (String)row1.NDate;
Can you please help?
Thanks
Date cannot be between two texts. Since your context variables is a String then use to_date function:
"select ... where my_date between to_date("
+TalendDate.formatDate("ddMMyyyy",TalendDate.addDate(new Date(), 2, "MM"))+
",'DDMMYYYY') and
+TalendDate.formatDate("ddMMyyyy",TalendDate.addDate(new Date(), 5, "MM"))+
");"

Why do I need to parse dates in Grails?

I am in the unfortunate position that I need to use a composite id in a Grails app where I work with legacy data. This means I have to override some actions in the controller, but as I did this I was struck by the fact that I could not use use a date argument directly as a parameter to a dynamic method.
Instead of just doing MyLegacyObj.findBySystemIdAndLogDate(params.systemId, params.logDate), I first needed to parse the date string before giving it to the dynamic method. To further complicate matters I had no idea what format the date string had (until I added lots of log.debug() string to the output). So now I have a bit of code looking like this
def formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy")
MyLegacyObj.findBySystemIdAndLogDate(params.systemId, formatter.parse(params.logDate));
This feels unoptimal, no to say dangerous (what if the date format changes with the locale?)? What would be a recommended way of doing this, and do I really need to parse dates at all?
Date is a pretty complex object and params are just Strings, so Date is submitted in parts. It is "magically" assembled from the parts when assigning x.properties = params.
Command object will do the work for you, if you add a Date field to it.
It has nothing to do with methods' dynamic or static invocation. Your GSP that renders Date editor might interfere too.