I was working on a project and I need to save cron expressions on either a weekly or monthly basis. Monthly crons are created on a nth day of the week. I am using cron-utils to create the cron, and found on this article that Spring Cron supports an nth day of the week. However as I have written the code, I have found little to no support for the nth day of the week using a hash. I have searched the internet and have not found a definitive answer as to whether or not spring supports the nth day of the week. So, does Spring Cron support the nth day of the week or not?
Before you answer to not add the tag, just think I want something to run "every 2nd Wednesday of each month".
I just checked, and the feature is supported by Spring, and cron-utils as well. Below the appropriate code:
import org.springframework.scheduling.support.CronExpression;
CronExpression.parse("0 0 0 ? * WED#2");
This would run the cron the second Wednesday in the month at midnight. A similar example is provided in the docs.
In cron-utils you can parse the same expression with the following code:
import com.cronutils.model.CronType;
import com.cronutils.model.definition.CronDefinitionBuilder;
CronParser parser = new CronParser(
CronDefinitionBuilder.instanceDefinitionFor(CronType.SPRING)
);
parser.parse("0 0 0 ? * WED#2");
Related
i'm currently looking for a solution for sometimes now,
i have this cron expression
time := '0 3,10,16,22 * * ?'
and i need to parse this into date and compare it to get a result
what my goal is to get time data from the time var and compare it,
if the time is not in between 00:00 and 00:06 it will return bool false
i understand for comparison i can use if clause but,
how to parse this cron expression and turn it into date solution were not found yet.
i've been reading cron package in godoc for sometimes and dont find it yet maybe i'm missing something?
any kind of solution or input were appreciated thanks!
You could use the package cronexpr from aptible/supercronic:
import "github.com/aptible/supercronic/cronexpr"
import "time"
nextTime := cronexpr.MustParse("0 3,10,16,22 * * ?").Next(time.Now())
Now that you have the next time, you can check if it is between 00:00 and 00:06.
I have a channel entries tag that I am trying to order by a custom date field that is used for the day, then I want to sort them by another custom field that is used for the start time.
The ordering and sorting works properly until an entry gets edited. The edit_date then takes precedence and the entry gets moved to the top.
Below is the basic Expression Engine markup I am using:
day-of-week = Expression Engine date field
start-time = Third-party installed field type from Devotee https://devot-ee.com/add-ons/time-select
{exp:channel:entries channel="{segment_1}" category="12" orderby="day-of-week|start-time" sort="asc|asc" sticky="no"}
<span>{day-of-week format="%D"}">{session_date format="%D. %M. %d, %Y"}</span>
<span>{start-time format="%g:%i %a"} - {end-time format="%g:%i %a"}</span>
I ended up breaking up my channel entries into three separate blocks that corresponded to each day of the week that I needed - Wednesday, Thursday, and Friday. That way I only had to order/sort by one parameter - the time.
I have a column called Start Time (it's a SharePoint Default Calendar Column). I need to validate if the Start Time is less than today or not? Without using javascript? Is this possible?
I have tried this:
Created a column called Today type as Date and Time.
Default value is current date.
Then compared the Start Time and Today in validation settings like the following:
=[Start Time] < [Today]
it seems not working. help please?
Try this code instead of yours
=[Start Time]<NOW()
I use this to validate that Start Date must be less than or equal to Today:
=[Start Date]<=Today()
...and it works for me.
I building a custom user control in asp.net where the user can enter in a date. I am already using a JQuery function that puts in a date mask in the format of dd/mm/yyyy, but I am unable to find another JQuery function(s) or one that combines all my needs.
What I am also looking for is:
1) To validate whether the date is really a date, i.e. not 31/13/2010 or anything along those lines.
2) Where I can check to see whether a date is in the past or in future based upon a configuration entry in the application.
Can anyone help me, please?
This is just off the top of my head, but you could use JavaScript's Date object http://www.w3schools.com/jsref/jsref_obj_date.asp
1) You could use one of the following
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Then verify that the date components are the same as entered. If you set the month to 50, it will take the year, and go 50 months forward... which seems odd, but... Just have to verify the information is what you entered. The months start at 0 for January, so when checking, be aware of that.
2) There's probably a lot of ways to do this check, but a quick thought on it is
var t = d.getTime() - new Date().getTime();
If t is positive, it's in the future, if it's negative it's in the past.
The new Date() creates a date object with the current time.
You could also use the jQuery UI DatePicker. http://jqueryui.com/demos/datepicker/
I haven't checking into the exact functionality it has that might fit your requirement, but it is another resource to check into.
HTH
I have the following times stored in an XML document, which correspond to the time when the document was created and then updated:
<create-time>2010-11-04T03:13:35.212Z</create-time>
<update-time>2010-11-03T20:18:26.331-07:00</update-time>
The document was created at 8:13 pm, and then updated 5 minutes later, at 8:18 pm, but when I show the creation dates with format-dateTime(xs:dateTime(.), '[M]/[D]/[Y]'), I get 11/4/2010 and 11/3/2010, as if the document was updated one day before it was had been created, which is obviously not the case. How can I fix this?
The create-time and update-time in your XML document are correct, but they use different timezones:
create-time is in UTC (also called Zulu time, hence the Z).
update-time is in Pacific time.
This can happen if different pieces of code set this the time, or even from the same code using different libraries or functions. For instance, if you are using XPath from XForms:
Using current-dateTime() uses a timezone from the dynamic context, which is often the current timezone for the machine on which the code is running.
Using now() always returns a UTC time.
The solution in XPath is to use the adjust-dateTime-to-timezone() function. This will normalize your dateTimes so they are in the same timezones. As an example, in an XForms output, to show just the date part of create-time you would use:
<xforms:output value="format-dateTime(adjust-dateTime-to-timezone(xs:dateTime(create-time)), '[M]/[D]/[Y]')">
<xforms:label>Creation date</xforms:label>
</xforms:output>