I am new to this code.
While running automation script, the date is automatically picked todays date.
actually the date starts from 01/01/2022.
How to change this code?
public void validateStartDateDefaultValueNew() throws Exception{
Date date = Calendar.getInstance().getTime();
DateFormat date formatter = new SimpleDateFormat( pattern: "dd/MM/yyyy");
String today = dateformatter.format(date);
System.out.println("today is "+today);
System.out.println("formatted today is "+date formatter.parse(today))
String [] actual1 = searchStartDateInput.getAttribute("value").split(regor " ");
String actual actuall[0]; =
System.out.println("today actual app is [+actual);
Assert.assertEquals(today, actual);
In your code, you mentioned -
'Date date = Calendar.getInstance().getTime();'.
This line of code takes today's date and current time.
If you want the start date to be '01/01/2022', then hard-code it in your code.
Related
I am wanting to display in a react native app a date given by the API.
The API is returning the following value:
"2022-06-20T14:00:00.000"
I need to display to the user
2:00 PM
The problem is that when I try this:
const dateString = "2022-06-20T14:00:00.000"
const date = new Date(dateString);
console.log(date)
The date has been changed to:
2022-06-20T14:00:00.000Z
Meaning it is 2pm UTC time when it should be 2pm local time.
On the end of the new Date variable, if you add the .toLocaleTimeString(), it should then output as 2:00:00PM.
const date = new Date(dateString).toLocaleTimeString();
you can use moment library with its localized formats,
here is the documentation for more of its formats https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/
const dateString = "2022-06-20T14:00:00.000"
console.log(moment(dateString).format('LT'))
I am trying to run a query at the repository level of my nestjs application.
The date format of the column (runDateTime) in my DB is isoString. I want to find all the records that have runDateTime of today's date.
I have a function called Parsebackenddate that essentially converts iso string to YYYY-MM-DD. how do i use this function with "schedule.runDateTime" in order to compare both dates in the format YYYY-MM-DD?
Or is there an alternative?
if (getToday) {
const todayDate = dayjs().format('YYYY-MM-DD');
query.where('schedule.runDateTime = :todayDate', {
todayDate,
});
``
Much appreciated.
first, you have to get a date from the database and hold it in a class variable then compare.
something like that may this could help.
var _orderBean = new date_beans();
_orderBean.dueDate = _response[a].dueDate.toISOString().slice(0,10); //YYYY-MM-DD
then compare
var d = new Date(); //todaydate
if(d.toISOString().slice(0,10)>_orderBean.dueDate)
// TodayDate > DueDate
I'm trying to compare the date of videos on a webpage to today's date. If the difference between the two dates is more than X days, report back as false.
The videos on the webpage have a tag in them which uses the format yyyy-mm-dd
I've got a selector set up to find the videos const videoDate = Selector('OPTA-video').withAttribute('data-secondary-time')
Now how do I set a variable to today's date and compare the two? I'm completely stuck!
I was using Katalon Studio before and here's the groovy script that did the same job:
String videoDate = WebUI.getAttribute(findTestObject('OPTA-video'), 'data-secondary_time')
LocalDate todaysDate = LocalDate.now()
LocalDate videoDateParsed = LocalDate.parse(videoDate, dtf)
if (ChronoUnit.DAYS.between(videoDateParsed, todaysDate) > 1) {
KeywordUtil.markFailed('The videos are 2+ days old.')
} else {
KeywordUtil.logInfo('The videos are up to date.')
}
You can use the getAttribute TestCafe method to access an attribute value. Then, parse the attribute value into the JavaScript Date object:
String videoDate = Selector('OPTA-video').getAttribute('data-secondary-time');
Date videoDateParsed = Date.parse(videoDate);
Date todaysDate = Date.now()
...
In the following thread you can find how to compare Date objects.
This is one of the scripts that I am using.
//getting your XPath test value into a string
String ann_time =
WebUI.getText(findTestObject("ObjectRepository/navigateTOElement/announcements_date"))
//converting time to simple date format
SimpleDateFormat sdf = new SimpleDateFormat('HH:mm')
Date sdf_anntime = sdf.parse(new String(ann_time))
//getting Current time
SimpleDateFormat dateFormatGmt = new SimpleDateFormat('HH:mm')
dateFormatGmt.setTimeZone(TimeZone.getTimeZone('GMT'))
SimpleDateFormat dateFormatLocal = new SimpleDateFormat('HH:mm')
currDate = dateFormatLocal.parse(dateFormatGmt.format(new Date()))
// time gap in long format
long duration = currDate.getTime() - sdf_anntime.getTime()
//time gap to mins
long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration)
//compare time gap with globale variable
if (diffInMinutes < GlobalVariable.News_updated_time) {
log.logInfo("system is getting updated,last updated "+ diffInMinutes + "min ago")
} else {
CustomKeywords.'errorMessage.logFailed.markStepFailed'('from 1 h, system was not updated')
log.logInfo('from '+ diffInMinutes+ 'h, system was not updated')
}
As part of an opening times page, I want to parse a DayOfWeek range as (Monday to Friday) rather than creating a String for every day of the working week. Is there a way that this can be done so that the default locale automatically changes the range? I also expect TalkBack to say the text in Desired output when it is selected.
Desired output
English: Monday to Friday
English (US): Monday through Friday
French: du lundi au vendredi
Japanese: 月曜日から金曜日まで
Current code
String dayMonday = DayOfWeek.MONDAY.getDisplayName(TextStyle.FULL, Locale.getDefault())
String dayFriday = DayOfWeek.FRIDAY.getDisplayName(TextStyle.FULL, Locale.getDefault())
myTv.text = dayMonday + dayFriday
Current result
MondayFriday
Horribly belated answer, but to detail the point I was trying to get across in my comment.
Having language files for this which specify the structure of the phrase, as well as another one for the days of the week.
For example, you could have your phrasing files like:
phrasing.properties:
phrasing.dayrange=%1$s to %2$s
phrasing_en_US.properties:
phrasing.dayrange=%1$s through %2$s
phrasing_fr_FR.properties:
phrasing.dayrange=du %1$s au %2$s
Note there is no requirement for spaces before/after the %n$s points. String.format (which will eventually be used, see below) has no such restriction.
And then have your day-name files as:
daynames.properties:
dayname.monday=Monday
dayname.tuesday=Tuesday
...
daynames_fr_FR.properties:
dayname.monday=Lundi
dayname.tuesday=Mardi
And then in your code you do something like:
/**
* Expects {#code fromDay} and {#code toDay} to be
* {#code Strings} in the format {#literal "monday"},
* {#literal "tuesday"}, etc. <emph>in English</emph>.
*/
public String formTheString(final String fromDay,
final String toDay) {
final ResourceBundle phrasingBundle = ResourceBundle.get("phrasing");
// Get the phrasing format: '%1$s ...' style
final String phrasing = phrasingBundle.getString("dayrange");
final ResourceBundle dayNameBundle = ResourceBundle.get("daynames");
// Get the translated day names
final String localisedFromDay = dayNameBundle.getString(fromDay);
final String localisedToDay = dayNameBundle.getString(toDay);
// Use the 'phrasing' as a format, passing in
// the translated day names as the parameters
// to it.
return String.format(phrasing, localisedFromDay, localisedToDay);
}
Alternatively to the 'dayname' files, you can do what the other answer here suggested.
This may help you. This gets a calander, sets it to the first day of the week.
Then, creates a formatter that outputs the day name, for a particular Locale - in this case France, but you can change it to what you like.
Finally, it prints out the day name, adds 5 days, then prints out the dayname again.
public static void main(String arg[]) {
GregorianCalendar cal = new GregorianCalendar();
cal.set(cal.DAY_OF_WEEK,cal.getFirstDayOfWeek());
SimpleDateFormat sdf = new SimpleDateFormat("EEEEEEEEEE", Locale.FRANCE);
System.out.println(sdf.format(cal.getTime()));
cal.add(cal.DAY_OF_WEEK, 5);
System.out.println(sdf.format(cal.getTime()));
}
For this example, I get the output:
lundi
samedi
I am using ChannelSftp(jsch-0.1.42.jar) to copy files from a unix server and can successfully do it but the last modified date gets overwritten by the current time.
I am using
chanSftp.get(nextName, "C:/Test/" + nextName);
Is there any way of retaining the last modified time of the remote file on the local copy?
I have the last modified time of the remote file which i got using
attrs = lsEntry.getAttrs();
Date modDate = (Date) format.parse(attrs.getMtimeString());
Using a SimpleDateFormat is of less performance. Instead one could use the methods getMTime() and getATime() directly. But they deliver a value reduced by the milliseconds.
That's why they return an int and not a long as expected in conformance to date.getTime().
SftpATTRS attrs = lsEntry.getAttrs();
Date dateModify = new Date(attrs.getMTime() * 1000L);
Date dateAccess = new Date(attrs.getATime() * 1000L);
In jsch-0.1.50 be careful of using getAtimeString() there is the factor 1000L missing.
In jsch-0.1.51 the getAtimeString() bug with the missing factor is fixed.
This changes the last modified time of the file downloaded from the remote server,
String remoteFilePath = "testDir/testFile.txt";
SftpATTRS attrs = sftpChannel.lstat(remoteFilePath);
SimpleDateFormat format = new SimpleDateFormat(
"EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
Date modDate = (Date) format.parse(attrs.getMtimeString());
String localFilePath = "C:/temp/downloadedFile.txt";
sftpChannel.get(remoteFilePath, localFilePath);
File downloadedFile = new File(localFilePath);
downloadedFile.setLastModified(modDate.getTime());
Merging the answers above to a working solution:
sftpChannel.get(REMOTE_FILE, LOCAL_FILE);
SftpATTRS attrs = sftpChannel.lstat(REMOTE_FILE);
Date dateModify = new Date(attrs.getMTime() * 1000L);
File downloadedFile = new File(LOCAL_FILE);
downloadedFile.setLastModified(dateModify.getTime())