Cron expression with start and end time - cron

I am trying to write an cron expression with a specific start time and end time everyday. i.e.
every minute from 10:15 to 17:35 everyday
One possible solution for this is writing 3 different cron expressions like this:
0 15-59 10 * * *
0 * 11-17 * * *
0 0-35 17 * * *
Is there any possible way to write this in one single cron expression ?

There is no other way to achieve it using single crone expression but to specify multiple crone expressions for specific startDate and endDate.
There is a slight modification in second crone expression though (highlighted one)
0 15-59 10 * * * (Every minute between 10:15 AM and 10:59 AM)
0 * 11-16 * * * (Every minute, between 11:00 AM and 04:59 PM)
0 0-35 17 * * * (Every minute between 05:00 PM and 05:35 PM)

Quartz Scheduler c#
run job between to hours
use corn mask:
ITrigger trigger_1 = TriggerBuilder.Create()
.ForJob("YOUR_JOB")
.WithIdentity("trigger_1")
.StartAt(startTime)
.WithCronSchedule("0 0/1 8-13 ? * SUN,MON,TUE,WED,SAT *")
.Build();
use Quartz Schedule:
trigger_1 = TriggerBuilder
.Create()
.ForJob("YOUR_JOB")
.WithIdentity("trigger_1")
.StartAt(startTime)
.WithDailyTimeIntervalSchedule(c => c
.OnEveryDay()
.WithIntervalInMinutes(1).WithRepeatCount(1)
.StartingDailyAt(new TimeOfDay(08, 30))
.EndingDailyAt(new TimeOfDay(12, 30))
)
.Build();

HashMap<String, String> weekday = new HashMap<>();
// String strDays ="[Monday, Friday]";
String strCalDay = "";
String startDate[] = fromDate.split("-");
String endDate[] = toDate.split("-");
weekday.put("MONDAY", "1");
weekday.put("TUESDAY", "2");
weekday.put("WEDNESDAY", "3");
weekday.put("THURSDAY", "4");
weekday.put("FRIDAY", "5");
weekday.put("SATURDAY", "6");
weekday.put("SUNDAY", "7");
strDays = strDays.replace("[", "").replace("]", "");
String strDay[] = strDays.trim().toUpperCase().split(",");
if (strDay != null && strDay.length > 0) {
for (int i = 0; i < strDay.length; i++) {
strCalDay = strCalDay + "," + weekday.get(strDay[i].trim().replace("\"", ""));
}
// System.out.println(" No of days :: "+ strCalDay);
strCalDay = strCalDay.replaceFirst(",", "");
//System.out.println(" No of days :: "+ strCalDay);
}
Calendar startCal = Calendar.getInstance(TimeZone.getDefault());
Calendar endCal = Calendar.getInstance(TimeZone.getDefault());
startCal.set(Integer.parseInt(startDate[0].toString()),
Integer.parseInt(startDate[1].toString()),
Integer.parseInt((startDate[2].toString())));
endCal.set(Integer.parseInt(endDate[0].toString()),
Integer.parseInt(endDate[1].toString()),
Integer.parseInt((endDate[2].toString())));
int yearsInBetween = endCal.get(Calendar.YEAR) - startCal.get(Calendar.YEAR);
int monthsDiff = endCal.get(Calendar.MONTH) - startCal.get(Calendar.MONTH);
long ageInMonths = yearsInBetween * 12 + monthsDiff;
System.out.println(" ageInMonths: " + ageInMonths);
if (startCal.get(Calendar.MONTH) != endCal.get(Calendar.MONTH)) {
if (ageInMonths == 3) {
Calendar middleMonth1 = (Calendar) startCal.clone();
middleMonth1.add(Calendar.MONTH, 1);
Calendar middleMonth2 = (Calendar) startCal.clone();
middleMonth2.add(Calendar.MONTH, 2);
int getFirstMMonth = middleMonth1.get(Calendar.MONTH);
int getSecMMonth = middleMonth2.get(Calendar.MONTH);
if (getFirstMMonth == 0) {
getFirstMMonth = 12;
System.out.println(" getFirstMMonth : " + getFirstMMonth);
}
if (getSecMMonth == 0) {
getSecMMonth = 12;
// System.out.println(" getSecMMonth : " +getSecMMonth );
}
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-" + "31,1-31,1-31,1-" + endDate[2] + " " +
startDate[1] + "," + getFirstMMonth + "," + getSecMMonth + "," + endDate[1] + " *";
// System.out.println(" expression for month3 : " + exp);
}
if (ageInMonths == 2) {
Calendar middleMonth1 = (Calendar) startCal.clone();
middleMonth1.add(Calendar.MONTH, 1);
//System.out.println(" get middleDate month : " + middleMonth1.get(Calendar.MONTH));
int getMiddleMonth = middleMonth1.get(Calendar.MONTH);
if (getMiddleMonth == 0) {
getMiddleMonth = 12;
// System.out.println(" getMiddleMonth : " +getMiddleMonth );
}
// System.out.println(" Outside getMiddleMonth : " +getMiddleMonth );
endCal.set(Calendar.MONTH, 11);
//System.out.println(" get middleDate month 001: " + endCal.get(Calendar.MONTH));
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-" + "31,1-31,1-" +
endDate[2] + " " + startDate[1] + "," +
getMiddleMonth + "," + endDate[1] + " *";
// System.out.println(" get end month2 : " + exp);
} else if (ageInMonths == 1) {
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-31,1-" +
endDate[2] + " " + startDate[1] + "," + endDate[1] + " *";
//System.out.println(" expression for one month : " + exp);
}
} else {
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-" + endDate[2] + " " + endDate[1] + " *";
}
System.out.println(" expression for before parameter : " + exp);
//Run with only Start Date
if (strRepeat != null && strRepeat.equalsIgnoreCase("No")) {
exp = strTimeMin + " " + strTime + " " + startDate[2] + " " + startDate[1] + " *";
} else if (strRepeat != null && strRepeat.equalsIgnoreCase("Daily")) {
exp = exp;
} else if (strRepeat != null && strRepeat.equalsIgnoreCase("Weekdays")) {
// System.out.println(" expression for weekdays before : " + exp);
exp = exp.replace("*", strCalDay);
// System.out.println(" expression for weekdays after : " + exp);
} else if (strRepeat != null && strRepeat.equalsIgnoreCase("Weekends")) {
// System.out.println(" expression for weekend before : " + exp);
exp = exp.replace("*", "6,7");
// System.out.println(" expression for weekend after : " + exp);
}
System.out.println(" cron expression ::: " + exp);

Related

How can I format this String with double x,y,total to two decimal places. output = (x + " + " + y + " = " + total);

How can I format this String with double x,y,total to two decimal places. String output = (x + " + " + y + " = " + total);
String ouput = String.format("%.2f + %.2f = %.2f",x,y,total);
System.out.println(output);
will give you the output with 2 decimal places or you can use DecimalFormat as well.

Update drop down list dynamically - xpages

I have a form with two drop down type ahead fields. The first one works but the second one has to use different views based upon the input of the first value (actually a viewScope variable stored after the first is input). The second drop down is empty no matter what is typed into the first one. I will include the code I have for the selectItems for the second field below. I also will include the visible code to only display the second field for certain circumstances. Can you please take a look at what I have? Thanks for your help. (the views in the code are all data sources)
switch(viewScope.vsTieIn) {
case "0046":
return viewAceLkup.getColumnValues(0) + viewAceLkup.getColumnValues(1) + viewAceLkup.getColumnValues(2) + "|" + viewAceLkup.getColumnValues(0);
break;
case "0009":
return viewDIBLkup.getColumnValues(0) + viewDIBLkup.getColumnValues(1) + viewDIBLkup.getColumnValues(2) + "|" + viewDIBLkup.getColumnValues(0);
break;
case "0166":
return viewOrgillLkup.getColumnValues(0) + viewOrgillLkup.getColumnValues(1) + viewOrgillLkup.getColumnValues(2) + "|" + viewOrgillLkup.getColumnValues(0);
break;
case "0016":
return viewPPGLkup.getColumnValues(0) + viewPPGLkup.getColumnValues(1) + viewPPGLkup.getColumnValues(2) + "|" + viewPPGLkup.getColumnValues(0);
break;
case "0005":
return viewTrueValueLkup.getColumnValues(0) + viewTrueValueLkup.getColumnValues(1) + viewTrueValueLkup.getColumnValues(2) + "|" + viewTrueValueLkup.getColumnValues(0);
break;
case "0026":
return viewAllProLkup.getColumnValues(0) + viewAllProLkup.getColumnValues(1) + viewAllProLkup.getColumnValues(2) + "|" + viewAllProLkup.getColumnValues(0);
break;
}
VISIBLE CODE:
getComponent("DropShip").getValue() ||
viewScope.vsTieIn == "0046" ||
viewScope.vsTieIn == "0009" ||
viewScope.vsTieIn == "0166" ||
viewScope.vsTieIn == "0016" ||
viewScope.vsTieIn == "0005" ||
viewScope.vsTieIn == "0026";
Here is the xsp code:
<xe:djFilteringSelect
id="djFilteringSelect1"
value="#{document1.CustInput}"
ignoreCase="true"
promptMessage="Enter a Customer ID, Phone or Name"
invalidMessage="Invalid Entry - check spelling"
style="width:150px"
autoComplete="true">
<xe:this.rendered><![CDATA[#{javascript:getComponent("DropShip").getValue() ||
viewScope.vsTieIn == "0046" ||
viewScope.vsTieIn == "0009" ||
viewScope.vsTieIn == "0166" ||
viewScope.vsTieIn == "0016" ||
viewScope.vsTieIn == "0005" ||
viewScope.vsTieIn == "0026";}]]></xe:this.rendered>
<xp:selectItem
itemLabel=""
id="selectItem2">
</xp:selectItem>
<xp:selectItems id="selectItems1">
<xp:this.value><![CDATA[#{javascript:switch(viewScope.vsTieIn) {
case "0046":
return viewAceLkup.getColumnValues(0) + viewAceLkup.getColumnValues(1) + viewAceLkup.getColumnValues(2) + "|" + viewAceLkup.getColumnValues(0);
break;
case "0009":
return viewDIBLkup.getColumnValues(0) + viewDIBLkup.getColumnValues(1) + viewDIBLkup.getColumnValues(2) + "|" + viewDIBLkup.getColumnValues(0);
break;
case "0166":
return viewOrgillLkup.getColumnValues(0) + viewOrgillLkup.getColumnValues(1) + viewOrgillLkup.getColumnValues(2) + "|" + viewOrgillLkup.getColumnValues(0);
break;
case "0016":
return viewPPGLkup.getColumnValues(0) + viewPPGLkup.getColumnValues(1) + viewPPGLkup.getColumnValues(2) + "|" + viewPPGLkup.getColumnValues(0);
break;
case "0005":
return viewTrueValueLkup.getColumnValues(0) + viewTrueValueLkup.getColumnValues(1) + viewTrueValueLkup.getColumnValues(2) + "|" + viewTrueValueLkup.getColumnValues(0);
break;
case "0026":
return viewAllProLkup.getColumnValues(0) + viewAllProLkup.getColumnValues(1) + viewAllProLkup.getColumnValues(2) + "|" + viewAllProLkup.getColumnValues(0);
break;
}
}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler
event="onChange"
submit="true"
refreshMode="partial"
id="eventHandler10" refreshId="custTable">
<xe:this.action><![CDATA[#{javascript:var compID = getComponent("djFilteringSelect1").getValue();
var custDoc:NotesDocument = viewCustByID.getDocumentByKey(compID);
//Set Billing Info
document1.setValue("BillCompID", custDoc.getItemValue("CustID"));
viewScope.vsBillCompID = custDoc.getItemValue("CustID");
viewScope.vsBillFax = custDoc.getItemValue("CustFax");
//Set Shipping Info
document1.setValue("ShipCompName", custDoc.getItemValue("CustShipName"));
document1.setValue("ShipAddr1", custDoc.getItemValue("CustShipAddr1"));
document1.setValue("ShipAddr2", custDoc.getItemValue("CustShipAddr2"));
document1.setValue("ShipAddr3", custDoc.getItemValue("CustShipAddr3"));
document1.setValue("ShipCity", custDoc.getItemValue("CustShipCity"));
document1.setValue("ShipState", custDoc.getItemValue("CustShipState"));
document1.setValue("ShipZip", custDoc.getItemValue("CustShipZip"));
document1.setValue("ShipProv", custDoc.getItemValue("CustShipProv"));
document1.setValue("ShipCountry", custDoc.getItemValue("CustShipCntry"));
var a = custDoc.getItemValue("CustBillName");
var b = custDoc.getItemValue("CustBillAddr1");
var c = custDoc.getItemValue("CustBillAddr2");
var d = custDoc.getItemValue("CustBillAddr3");
var e = custDoc.getItemValue("CustBillCity");
var f = custDoc.getItemValue("CustBillState");
var g = custDoc.getItemValue("CustBillZip");
var h = custDoc.getItemValue("CustBillProv");
var i = custDoc.getItemValue("CustBillCntry");
var j = custDoc.getItemValue("CustPhone");
viewScope.a = custDoc.getItemValueString("CustBillName");
viewScope.b = custDoc.getItemValueString("CustBillAddr1");
viewScope.c = custDoc.getItemValueString("CustBillAddr2");
viewScope.d = custDoc.getItemValueString("CustBillAddr3");
viewScope.e = custDoc.getItemValueString("CustBillCity");
viewScope.f = custDoc.getItemValueString("CustBillState");
viewScope.g = custDoc.getItemValueString("CustBillZip");
viewScope.h = custDoc.getItemValueString("CustBillProv");
viewScope.i = custDoc.getItemValueString("CustBillCntry");
viewScope.j = custDoc.getItemValueString("CustPhone");
document1.setValue("BillCompInfo", a + "<br />" + b + (c ? "<br />" + c : "") + (d ? "<br />" + d : "") + "<br />" + e + ", " + f + g + (h ? "<br />" + h + " " : "") + (i ? ", " + i : "") + (j ? "<br />" + j : ""));
document1.setValue("OrderStatus", "Draft");
viewScope.vsTerms = custDoc.getItemValue("CustTerms");
viewScope.vsDiscCode = custDoc.getItemValue("CustDiscCode");
viewScope.vsTradeDisc = custDoc.getItemValue("CustTradeDisc");
viewScope.vsTieIn = custDoc.getItemValue("CustTieIn");
viewScope.vsPromoCode = custDoc.getItemValue("CustPromoGroup");
viewScope.vsPromoBypass = custDoc.getItemValue("CustPromoBypass");
document1.setValue("djFilteringSelect1", "");
getComponent("djFilteringSelect1").setValue("");
if(document1.isNewNote()) {
var vUNID = session.evaluate("#Unique").elementAt(0);
document1.setValue("OrderUNID", vUNID);
viewScope.vsOrderUNID = vUNID;
}
}]]></xe:this.action>
</xp:eventHandler>
</xe:djFilteringSelect>
Take a look here http://tc-soft.com/blog/377
Your second combo has to be refreshed by the first one. So first combo must fire partial refresh to the area of second combo.

Get IP Address, Browser Type MVC 5

I need to get local system ip address and browser agent (firefox,chorme,ie,etc..) in MVC 5. Search google Request.ServerVariables["REMOTE_ADDR"] which is not working in MVC5
For getting IP Address use this code:
public static string GetIPAddress(HttpRequestBase request)
{
string ip;
try
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
{
if (ip.IndexOf(",") > 0)
{
string[] ipRange = ip.Split(',');
int le = ipRange.Length - 1;
ip = ipRange[le];
}
}
else
{
ip = request.UserHostAddress;
}
}
catch { ip = null; }
return ip;
}
https://stackoverflow.com/a/7348761/4568359
================================================================
And for getting browser info:
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string brw_info = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
https://msdn.microsoft.com/en-us/library/3yekbd5b.aspx
To get client IP Address
var IPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(IPAddress))
{
IPAddress = Request.ServerVariables["REMOTE_ADDR"];
}
To get client user agent.
var userAgent = Request.UserAgent;
You are looking for something like to get Ip address
HttpRequest.UserHostAddress Property
and check out this for browser detection 51Degrees.Mobi Foundation

Removing decimals from division result

I am currently developing a game, and I have a small problem.
When a player buys an item from a shop, I set it to be sold at 75% the buying price.
But when the value is checked (before selling the item) it says, for example, "Can be sold for 115.0 gold"
How do I remove the ".0" from the "115"?
I'm still new to coding, any help is appreciated.
(It's also shown with brackets, I would like to remove those as well. In example: "You can sell this for (120.0) gold pieces.")
Edit: This is java.
int ShopValue = (int)Math.floor(getItemShopValue(removeId, 1, removeSlot));
String ShopAdd = "";
if (ShopValue >= 1000000000) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1000000000) + " billion)";
} else if (ShopValue >= 1000000) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1000000) + " million)";
} else if (ShopValue >= 1000) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1000) + "k)";
} else if (ShopValue >= 100) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1) + ")";
} else if (ShopValue >= 10) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1) + ")";
}
c.sM(c.getItems().getItemName(removeId)+": shop will buy for <col=255>"+ShopAdd+"</col> coins");
}
}
simple way is use a integer type cast
(int)Math.floor(ShopValue*.75 / 1)
Math.floor is returning double parameter so u have to just convert it to int before you give it to ShopAdd string.

Beginner: concat a string from different primitives

Apologies, as I'm sure this is a stupid question, but...
Please could anyone explain to me why this:
public class java {
public static void main(String[] args) {
byte zero = 0;
short one = 1;
int three = 3;
long one2 = 1;
float onepointnought = 1.0f;
double onedotnone = 1.0;
char letterh = 'H';
char letterw = 'w';
char letterr = 'r';
char letterd = 'd';
boolean bool = true;
String output = letterh + three + one + one2 + zero + " " + letterw + zero + letterr + one + letterd + " " + (onepointnought+onedotnone) + " " + bool;
System.out.println(output);
} }
Is outputting:
77 w0r1d 2.0 true
I'm expecting it to say "H3ll0 w0r1d 2.0 true"
It's from the interactive online java tutorials over at http://www.learnjavaonline.org/
Thanks!
Neil.
In this sentence
String output = letterh + three + one + one2 + zero + " " + letterw + zero + letterr + one + letterd + " " + (onepointnought+onedotnone) + " " + bool;
the letterh contains 'H' whose ASCII value is 72 & the addition of three + one + one2 + zero is 5 because these are non-string variables, so it is displaying (72 + 5)77 in the result,
you must convert three , one , one2 , zero to sting variable

Resources