evaluate difference between 2 dates to make a transition possible - jira

Is this possible to evaluate the duration between a specified date on a form of a workflow, and the system date ? that what I want to do, in order to show (if this possible too) a short message if 1 day occurs since the specified date above, forbidding the transition of the status Closed to Reopened...
Thanks a lot,
Christophe

I think the Script Runner has a validator that does something like this but I can't find it. Then you could write a post function with the Script Runner. Otherwise it's back to creating a custom validator, as described in my book Practical JIRA Plugins (O'Reilly)

You can use the ScriptRunner plugin in addition with the following script in the validator section for the Reopened transition:
Date now = new Date()
Date cfDate = new Date(cfValues['YourCustomField'].getTime())
new Date(now.getYear(), now.getMonth(), now.getDate()).compareTo(cfDate) <= 0
Replace YourCustomField with the name of your custom field. This will ensure that the transition will check whether the current date is beyond the date set in the custom field, and blocks it if it is.

First of all, thank you for your answer.
It works to allow transition when dates are similar, but my purpose was modified by my responsible. He would like to allow the transition if dates are similar or if the duration between them is only 1 day or less.
Example :
System date is 09/07/2013 (Paris)
My date (dd/mm/yyyy format) Transition allowed Why
07/07/2013 NO my date is former to system date
08/07/2013 NO my date is former to system date
09/07/2013 YES my date and system date equals
10/07/2013 YES only 1 day occur between 2 dates
11/07/2013 NO 2 days occur between 2 dates
Here is the code I wrote in order to do that, but it does'nt work (maybe a Java syntax error?) :
Date now = new Date()
Date cfDate = new Date(cfValues['Date de clôture réelle de la demande'].getTime())
new Boolean(((now.getTime() - cfDate) / 86400000) <= 1) && (now.getTime() >= cfDate ))
Excuse me for my english. I'm french, and I try to improve my English.
Thanks a lot.

Related

What Date Class is used in grails?

I want to get the 4-digit year from today.
I have a variable def todayDate = new Date() in my controller.
I googled to see how to do it. It pointed me to this page.
https://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/Date.html
There is a method called toYear()
Actually, none of the methods in this document works. The Date class in this document is not the same Date class in the controller for sure.
Did Google show me the wrong document? What is the correct way to get the 4-digit year from a Date()?
I was reading and trying to understand all the comments and checking the links. I think I get what is going on here.
When I declare a Date variable in Grails, it is a java.util.Date. If I google how to work with the Date, this gets confusing. The methods that process the Date are not from the java.util.Date class. Majority of the java.util.Date methods are deprecated. The methods you can find from google are actually coming from the org.codehaus.groovy:groovy-dateutil:3.0.9 Groovy date enhancement package.
So, the Date is a java.util.Date but the methods are from the enhancement package.
tl;dr
You said:
I want to get the 4-digit year from today.
String.valueOf( LocalDate.now().getYear() ) // Java syntax.
2022
Avoid legacy classes
The java.util.Date class is terribly flawed. Along with Calendar and the other legacy date-time classes, these were years ago supplanted by the modern java.time classes defined in JSR 310.
Sun, Oracle, and the JCP community all gave up on these legacy classes. I suggest you do the same.
Year
(Forgive the Java syntax as I do not know Groovy.)
If all you want is the year, use Year class.
Year currentYear = Year.now( z ) ;
int y = currentYear.getValue() ;
LocalDate#getYear
For a date-only value, use LocalDate.
Time zone
Determining the current date requires a time zone. For any given moment, the date varies around the globe by time zone.
(Again, Java syntax.)
ZoneId z = ZoneId.of( "America/Edmonton" ) ; // Or, ZoneId.systemDefault() ;
LocalDate today = LocalDate.now( z ) ;
int year = today.getYear() ;
I do not see all these methods in your Groovy API documentation. Perhaps I do not know how that doc works. The classes listed here are built into Java 8 and later.

I need to define a custom work week in MS access

I am trying to create a custom function on a form to define a week Number.
I have created a table that defines the week number.
Example WeekNo, StartDay, End Day
example: WeekNo 1 StartDay = 3/29/2020, End Day 4/4/2020
I have a Date box on my form if I enter a date of 3/29/2020
I would like 1 to be populated in my week number box.
On my form in the row source I have designed a Dlookup query
=DLookup("[WeekNumber]", "tblWeekNumber", "[Startdate] >= " & frmSearchNew.dt_Date & "") & [EndDate] <= frmSearchNew.dtDate
When I change to from view I get the error the record source specified on this form does not exist.
The table tblWeekNumber has the fields ID, WeekNo, StartDay and EndDay.
Where am I going wrong? any help is appreciated.
There are quite a few issues with the DLookup that you have put together.
Firstly, the field that you are looking for and the fields that you are using as criteria do not appear to match those in the table - WeekNumber/WeekNo, StartDate/StartDay, EndDate/EndDay;
Next, the logic for the lookup is wrong. You are trying to find a the week number that has a start date that is greater than the entered date, and an end date that is less than the entered date. What you should be looking for is a start date before the entered date, and an end date after the entered date.
Finally, dates are a bit funny in Access. You need to wrap them in '#' so that Access knows they are dates, and you should also take care to disambiguate them - 03/04/2020 could be either 3rd April or 4th March depending on you nationality.
Putting it all together, the final control source should look like:
=DLookUp("WeekNo","tblWeekNumber","StartDay<=#" & Format([dt_Date],"dd-mmm-yyyy") & "# AND EndDay>=#" & Format([dt_Date],"dd-mmm-yy") & "#")
Regards,

How to mark a delay of 2 *working days* (or more) in a task?

We're using the following rule to mark work items that delay 2 days or more:
Changed Date <= #Today - 2
Work Item Type = Task
State = In Progress
(Then, color the task in red)
The problem is that when a task gets started on Friday, on Monday it will be red, even though only one working day has passed.
Is there a way around this?
This is not available to do this. For Changed Date field:
Change Date
The date and time when a work item was modified.
Reference name=System.ChangedDate, Data type=DateTime.
Since using data time type, it's not able to auto exclude weekends, this is by designed for now.
State Change DateThe date and time when the value of the State field changed.
DateTime
= , <> , > , < , >= , <= , =[Field], <>[Field], >[Field], <[Field], >=[Field], <=[Field], In, Not In, Was Ever Macros: #StartOfDay, #StartOfWeek, #StartOfMonth, #StartOfYear, and #Today; each of these
macros can be specified with a +/- n interger.
There has also been a related feature request:
Add option to exclude weekends when setting up Styling rules using the 'Changed Date' field rule criteria
https://developercommunity.visualstudio.com/idea/376310/add-option-to-exclude-weekends-when-setting-up-a-s.html
You could vote up it and our PM will kindly review it. Unfortunately, we do not have any perfect solution/workaround, you may have to manually change/update the colored task based on those tasks which get started on Friday.

grails ORM , how to search Date without time

I am using postrges db.
My domain has a date field:
java.util.Date requestedDate;
I am trying to search by date in my controller:
eq ("requestedDate", requestedDate)
This works fine, but the problem is that date and time has to be exactly matching for this. But in application the user will only enter the date to search items (like give me all requests which are made on 2014-02-05 and the browser application will add the current time to the request). So the comparison fails because the user entered time is different from the time during creation of the request.
I tried 'like' but it throws error.
How to compare only date part ?
You could do something like this:
Date now = new Date()
now.clearTime()
def results = Meeting.withCriteria {
between('date', now, now+1)
}
So this strips off the time portion of the current date, and then does a 'between' query (between midnight just gone and midnight 24 hours later).
Still it looks like there is no convenient way to realize this.
You need a small detour by computing the start of the day and the end of the day and use the between operator.
EDIT
I just saw now rcgeorge23 gave you the right example for doing this.

get time of Different Timezone

My task: I am going to run a contest world wide at my website. A problem setter will set problems from a specific area of the world setting a time and date of starting time of the contest. I have to show that time correctly all over the world so the the contest starts at a time everywhere of the world.
My Idea : I planed to get the time from the problem setter of his time zone using server site language like php time(), & will store to database converting to timezone= zero (0). And who are going to attend the contest I'll just add hour(s) of that time zone with my database time.
Need help: I have no Idea how to convert that timestamps to timezone 'zero', even how can I get the ±hour(s) of current timezone?
Thank you...
Step 1:
Let the user choose his timezone. You could fill a dropdown with values from this site: http://php.net/manual/en/timezones.php
Step 2:
Convert the timezone to servertime
$timezone_client = new DateTimeZone('America/Denver');
$timezone_server = new DateTimeZone('Pacific/Nauru');
$datetime = new DateTime('2013-01-25 12:00:00', timezone_client);
$datetime->setTimezone($timezone_server);
echo $datetime->format('Y-m-d H:i:s');
Timezone 0 = "UTC" (sometimes called GMT)
Your system / language will have a Timezone class, which provides difference to GMT/UTC

Resources