In the process of migrating one of my Win32 VCL application from Delphi 2006 to delphi XE6 I encountered the following issue :
One of my forms has a TMonthCalendar (plugged on a TPanel for the record) to help the user select a week to view in a graph. By week I mean Monday being the first day and Sunday the last (french locale). To achieve such a week selection pattern I set the multiSelect property to true and put the following code inside the CalendarClick event :
MonthCalendar1.MultiSelect := True;
//Temporarily storing the selected day in a variable
TempoDate := MonthCalendar1.Date;
//searching for the monday right before the selected day (by user)
while dayOfWeek(TempoDate) <> 2 do
TempoDate := IncDay( TempoDate , -1 );
//Setting the monday as the start date of the selection
MonthCalendar1.Date := TempoDate;
//Setting the Sunday as the last day of selection
MonthCalendar1.EndDate := IncDay(tempoDate, 6);
That used to work well on Delphi 2006 ( compiled on a win XP computer ).
Now that I have ported the same code to Delphi XE6 ( compiled on a win7 computer ) I have the following problems :
When clicking the right arrow (>) to switch to the next month it fails most of the time. It actually fails when the monday of the week containing the 1st of the next month is still in the previous month. Ex : switching from Sept '14 to Oct '14 fails because the monday before Oct. 1st is in september (Monday Sept. 29th).
So that brings me back to September.
On the other hand, switching from August 14 to September 14 works because Sept. 1st is a monday.
When clicking on the first days of the next month (the few grey one you can click on) the month doesn't switch anymore.
all that used to work before.
I've made some specific isolation tests :
Creating a minimal app under XE6 with the same behaviour -> still fails (of course)
Creating the same minimal app under Delphi 2006 -> it all work as expected.
My intuition is that the TMonthCalendar now takes the .Date property to define which month to show, while on D2006 it used to take .EndDate property.
Doesn't know if this is a VCL evolution or a microsoft MonthCalendar underlying component behaviour change (since i compiled on XP then SEVEN ).
Thanks for your help
Useful documentation :
http://docwiki.embarcadero.com/Libraries/XE7/en/Vcl.ComCtrls.TMonthCalendar
http://msdn.microsoft.com/en-us/library/system.windows.forms.monthcalendar(v=vs.110).aspx
Unfortunately I can't provide you with solution but athleast I have eplanation for current behavior.
The problem you are facing is the TMonthCalender controll itself and which date fields is trated as selected even when using multiselect.
If you take a good look you will notice that even when using multiselect one day always have doted square around it. That date controls which month is focused.
So now you need to figure out how to change that behavior working with multiple selection enabled. I laredy tried setting the Date and EndDate properties so that EndDate value was actually lower since I thought that doing so miygt force MonthCalendar to treat last day of the weak to be selected when detirmining which month is focused but it has no effect. But it has no effect.
As for finding starting and ending week date use these functions:
TempDate := MonthCalendar1.Date;
WeekStart := StartOfTheWeek(TempDate);
WeekEnd := EndOfTheWeek(TempDate);
Both of these functions treat monday as fist day of the week.
I wish I could have helped you more.
Related
I'm facing date format problems in Delphi 10.4 CE.
If the date fields are created in SQL server with DateTime format, and a date field is incremented in the application with a specific number of days using the System.DateUtils.IncDay() function while the source date is 01/10/2022, I get the result as 01/09/1900 in the DBEdit component and in DBGrid when incremented by 10 days.
However, if I recreate date fields with formatting as Date fields (and not DateTime), the increment function shows errors like:
'' is not a valid date and time
Moreover, if I skip the increment function and add a record to the SQL table, the dates are shown in the format dd/mm/yyyy, but after adding records once, if I close the session and restart the application, all dates show up in the format yyyy-mm-dd.
Following is the source code to calculate the incremented date:
tblLeaveAzr.FieldByName('leaveend').AsDateTime := IncDay(tblLeaveAzr.FieldByName('leavestart').AsDateTime,tblLeaveAzr.FieldByName('leavedays').AsInteger);
I have been working in Delphi 6, 7 and 2009 for more than 20 years, but never faced such a problem.
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.
I have set standard VCL TDateTimePicker - MaxDate property to Date - e.g.
DTPicker.MaxDate := Date;
However, there is a problem. If I now set the date to be the current one:
DTPicker.Date := Date;
It will not accept it. The control simply stays at the date which is set at the design time. I can solve it by setting MaxDate to be Date + 1 and then setting the Date property works fine and shows today's date, but then user is able to select tomorrow's date. I also tried to set MaxDate to Date + 0.99999999 but that also is of no help.
I use Delphi 2010 and C++Builder 2010 (if this is a bug in either of them).
Any ideas how to prevent selecting any date beyond today and set the control date to today's date?
Changing the date results in - "Failed to set calendar date or time."
Update:
I managed to make it work as following:
open drop-down in TDateTimePicker (during runtime) and intentionally select Today's date (click on already selected Today's date)
after that select any past date
click button which has the code to reset the date and then it works.
My solution will likely be to use range-check before closing the form, as it seems that MaxDate is useless, at least with this version of Delphi.
It appears it's the time portion of Date that's causing the problem. This works fine on D2007, XE, XE8, and Delphi 10 Seattle:
DateTimePicker1.MaxDate := Trunc(Date) + 0.99999999999;
DateTimePicker1.Date := Date;
Tested using a brand new VCL forms application. Drop a TDateTimePicker and a TButton on the form, and generate an event for the FormCreate for the form:
procedure TForm1.FormCreate(Sender: TObject);
begin
DateTimePicker1.MaxDate := Trunc(Date) + 0.99999999999;
end;
and the button:
procedure TForm1.Button1Click(Sender: TObject);
begin
DateTimePicker1.Date := Date;
end;
Run the app, click the DateTimePicker combobox to display the calendar, and pick any date that's available. The DateTimePicker displays the selected date. Click the button, and the DateTimePicker updates to show today's date. Dropping down the calendar again shows the correct dates available.
Of course, as Remy Lebeau pointed out in a comment: in an actual application, you wouldn't want to hard-code the time portion. A better solution would be to use DateUtils.EndOfDay(Date) or Trunc(Date) + EncodeTime(23, 59, 59, 999).
There is no big difference between adding 1 and 0.99999, as 1 you would increment one day to the date, and 0.999999 it would be almost one day (something like 23:59:59:xxx).
Try the following (you have to include DateUtils in the uses list):
DTPicker.MaxDate := IncSecond(Date);
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.
We're on Team Foundation Server 2008 and I'm trying to find a way to report on the change in completed work from week to week at the task level. The MDX query below works pretty well, but I'd like to get rid of need to hard code last week's date. I've tried using prevmember and parallelperiod without success, but I'm no MDX expert.
WITH
MEMBER [Measures].[Completed Work by WI on dt1] AS
(
[Assigned To].[Person].CurrentMember,
[Work Item].[System_Id].CurrentMember,
[Date].[Year Week Date].[Week].&[2008-12-07T00:00:00],
[Measures].[Microsoft_VSTS_Scheduling_CompletedWork]
)
MEMBER [Measures].[Completed Work by WI on dt2] AS
(
[Assigned To].[Person].CurrentMember,
[Work Item].[System_Id].CurrentMember,
[Date].[Year Week Date].CurrentMember,
[Measures].[Microsoft_VSTS_Scheduling_CompletedWork]
)
MEMBER [Measures].[Completed Work] AS
[Measures].[Completed Work by WI on dt2] - [Measures].[Completed Work by WI on dt1]
SELECT
NON EMPTY
{
[Measures].[Completed Work]
}
ON COLUMNS,
NON EMPTY
{
Filter(
([Assigned To].[Person].[Person],[Work Item].[System_Id].[System_Id],[Work Item].[System_Title].[System_Title]), [Measures].[Completed Work] >0 )
}
ON ROWS
FROM [Team System]
Look at the provided Work Completed report. It automatically sets one of its date fields to today minus one month.
EDIT: Just logged into my work system to double check on this. The report is actually called "Remaining Work". Go to the SharePoint portal that was created for your Team Project, and find the list of standard reports. It'll be in that list. You can export that report to file, open it in Visual Studio and see the date field logic.
EDIT2: For an MDX function to get the previous week, try a variation on this: http://social.msdn.microsoft.com/Forums/en-US/tfsreporting/thread/0a656453-eaf1-47a2-a376-cb6eaec0db51
#sliderhouserules - I took a look at that report and it appears it is just taking the date entered and using the strtomember function. In my query, it looks like it would be the equivalent of the line with the hard coded date with:
StrToMember("[Date].[Year Week Date].[Week].&[" + Format(DATEADD("d", -7, "2008-12-21"), "s") + "]")
This works fine. However, what I really want is to eliminate the need to hard code anything. I tried using the Now() function instead of the hard coded date. I wasn't able to get it to work, but even if I did it would still mean that I'd need to change the number of days to subtract to get back to the Sunday of the previous week. It seems like there should be an MDX function that would make this work. If not, then perhaps there is some way to modify the StrToMember line to derive the previous Sunday's date in the proper format.