groovy next() date issue - date

I am trying to add a groovy script in SoapUI to find tomorrow's date using next() in current date.
I am getting the date as expected for all other dates except if the date is 19.
def TodaysDate = new java.util.Date().format("yyyy-MM-dd")
log.info ">>>>>>>>>> TodaysDate="+TodaysDate
log.info TodaysDate.next()
Output:
Wed Jul 19 14:34:29 EDT 2017:INFO:>>>>>>>>>> TodaysDate=2017-07-19
Wed Jul 19 14:34:29 EDT 2017:INFO:2017-07-1:
I tried this also.
def Today = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date())
log.info Today
NextDay = Today.next()
log.info NextDay
Output:
Wed Jul 19 14:43:38 EDT 2017:INFO:2017-07-19
Wed Jul 19 14:43:38 EDT 2017:INFO:2017-07-1:
This next() iterator works fine for other dates. Can you help me understand what I am doing incorrect here?

The format() method returns a String. And when you call next() on a String, it increments the last character. So, character 9 is incremented to the next unicode value, becoming :.
If you want your dates in a specific format, first you call next() in a Date object, then you format it:
def TodaysDate = new java.util.Date()
log.info ">>>>>>>>>> TodaysDate="+TodaysDate.format("yyyy-MM-dd")
log.info TodaysDate.next().format("yyyy-MM-dd")
The will print TodaysDate=2017-07-19 and the next date as 2017-07-20.

Maybe it's worth using TimeCategory in your case? Take a look at this simple code sample:
import groovy.time.TimeCategory
use (TimeCategory) {
println new Date() + 1.day
}
It works fine with any date. Test it with today's date (2017-07-19) - adding 1.day will give you 2017-07-20. Hope it helps.

Related

My selected date is showing one day before in Ionic 4

I am working in my Ionic 4 app and I have used a native datepicker for that and I am converting the date to toISOString() but the problem is that it is showing one day before.
This is my ts:
this.datePicker.show({
date: new Date(),
mode: 'date',
androidTheme: this.datePicker.ANDROID_THEMES.THEME_HOLO_DARK,
}).then(
date => {
me.acceptchallengeform.setValue({
startchallenge: new Date(date).toISOString().split('T')[0],
});
console.log('Got date: ', date)},
err => {
console.log('Error occurred while getting date: ', err)}
);
var DatePickerDate ='Thu Aug 09 2018 00:00:00 GMT+0100 (British Summer Time)';
var myDate = new Date(DatePickerDate).toISOString().split('T')[0];
so myDate is now 2018-08-08
The problem is that it is showing the date one day before.
But I want to show the exact selected date.
Any help is much appreciated.
new Date() return the date using your system timezone.
toISOString() return the date in UTC and the time part of your date is midnight, so it returns Thu Aug 08 2018 23:00:00 (BST - 1h), that's why you're getting one day before.
What are your trying to do exactly?
Editing my answer following comment
in your case I would choose the easy way as you apparently don't need any timezone information:
startchallenge: date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
or you can use moment.js (http://momentjs.com/docs/#/displaying/format/)
Try This:
date = new Date(date.setDate(date.getDate() + 1));
me.acceptchallengeform.setValue({
startchallenge: new Date(date).toISOString().split('T')[0],
});
This will solve your problem.

Angular2 - convert unfortunately date

I have a problem - I use c# Web.api and Angular2. Thats works but Angular convert the date which I do not want / need. The date of the database is correct and angular add 1 hour
{{item.createdate | date:'H:mm' }}
So it shows 20:30 instead of 19:30 which is stored in the database :(
This is part of json repsone:
"createdate": "2016-11-29T19:30:00",
How can I solve this?
Thank you
Ralf
The Reason is there's no timezone information in the datetime string from the database result.
var date = new Date('2016-11-29T19:30:00');
console.log(date); //Tue Nov 29 2016 20:30:00 GMT+0100 (CET)
Written in the Angular2 documentation about the Date Pipe here.
The expression expects a valid datestring format:
YYYY-MM-DDThh:mmTZD (eg 2016-11-29T19:30+01:00)
var date = new Date('2016-11-29T19:30+01:00');
console.log(date); // Tue Nov 29 2016 19:30:00 GMT+0100 (CET)

Issue saving a string as ISO date format

I'm trying to save a date to MongoDB from FullCalendar in my Grails application.
I'm trying to parse the string 2015-12-27T00:00:00.000Z into the below format:
def startDate = new Date().parse("YYYY-MM-dd'T'HH:mm:ss.SSSXXX",it.start)
def endDate = new Date().parse("YYYY-MM-dd'T'HH:mm:ss.SSSXXX",it.end)
But, weirdly when I print the formatted date, I get Sun Dec 28 05:30:00 IST 2014. I don't know what or how that particular date is picked.
You should use lowercase y for year. Uppercase Y is for "Week year".
new Date().parse("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "2015-12-27T00:00:00.000Z")
===> Sat Dec 26 19:00:00 EST 2015
import java.text.SimpleDateFormat;
println new SimpleDateFormat("yyyy-MM-dd HH:mm:ssX").parse("2018-07-30 09:57:15 +0800")

Convert Long date to specific short date format

Convert Long date format to specific short date format.
I want to get the Date from Datepicker(Jcalander) , format to dd-mm-yyyy format and assign to String variable. I tried using codes shown below. But didnt get the date format i want.
SimpleDateFormat simpleFormat = (SimpleDateFormat) jCalendarCombo1.getDateFormat();
Date date = jCalendarCombo1.getDate();
System.out.println(date); // Prints Thu Mar 28 00:00:00 IST 2013
String s = simpleFormat.format(date);
System.out.println(s); // prints Thursday, March 28, 2013
System.out.println("Date SHORT format: " + DateFormat.getDateInstance(DateFormat.SHORT).format(date)); // prints 3/28/13
If you want a fixed, non locale dependent format, you can just create it yourself;
SimpleDateFormat shortformat = new SimpleDateFormat("dd-MM-yyyy");
String s = shortformat.format(date);
System.out.println(s); // Prints 29-03-2013

How do I change constraints in a dojo DateTextBox dynamically?

I tried to do this:
dojo.mixin(endDate.constraints, {min: new Date(2009,09,14)});
But as a result I got this:
min Wed Oct 14 2009 00:00:00 GMT+0200 (CET)
??? It always adds one month! Is this a bug?
But what I actually want to do is something like this:
dojo.mixin(endDate.constraints, {min: dijit.byId("beginDate").date});
This results in:
min undefined
It's not a bug - it's a feature! And it's not a feature of Dojo, but JavaScript:
Integer value representing the month,
beginning with 0 for January to 11 for
December.
In order to debug that error, just use FireBug to see 1) what dijit.byId("beginDate").date returns - a string or a date object?, 2) if it's a string, is it correctly formatted; can new Date parse it?, etc...
Ben, as for the second part of your question, there is no date property on a DateTextBox. What you want is the value attribute
dijit.byId("beginDate").attr("value")
which does return a Date object.