Question
Can you change the format of the date on the date scaler?
We would like to change for example, “0502-08” to “May 02-08”, when at one week resolution.
Answer
Sure;
In GTP.NET you can set DateScaler.CultureInfoDateTimeFormat to change the date format to another cultural style to get the same effect in phGantTimePackage you must change the locales setting…
BUT you probably want to override the suggested output;
In GTP.NET Implement the event DateScaler.OnDateScalerDrawString and override the output by changing the argument e.OutputText.
Like this:
private void dateScaler1_OnDateScalerDrawString(PlexityHide.GTP.DateScaler dateScaler, PlexityHide.GTP.DateScalerDrawStringEventArgs e)
{
if (checkBoxMyOwnWeekPres.Checked)
{
// If you want to customize the way the date scaler draws its strings, you can…
if ((e.LongIntervall && e.Resolution==NonLinearTime.TimeResolution.days) && (!dateScaler1.UseDayNumbersNotWeeks))
{
// In this case we override the long intervall presentation when the resolution of the lower is Days ;
e.OutputText=e.DateTime.ToString(“MMdd”)+” – “+e.DateTime.AddDays(6).ToString(“MMdd”);
e.ContinueDraw=true;
}
}
}
Additional information from our friend Uli: I would like to change the DateScaler string. FAQ Q10070 describes a solution but there is a problem with the displayed DateTime which doesn´t agree to the displayed days. There is a small offset of three days. I did the following:
this.gantt1.DateScaler.OnDateScalerDrawString+=new DateScalerDrawStringEventHandler(DateScaler_OnDateScalerDrawString);
this.gantt1.DateScaler.TimeSpanSet(DateTime.Today, DateTime.Today.AddDays(20));
this.gantt1.DateScaler.UseDayNumbersNotWeeks=false;
this.gantt1.DateScaler.ShowWeekNumbers=false;
void DateScaler_OnDateScalerDrawString(DateScaler dateScaler, DateScalerDrawStringEventArgs e)
{
if((e.LongIntervall&&e.Resolution==NonLinearTime.TimeResolution.days)&&(!this.gantt1.DateScaler.UseDayNumbersNotWeeks))
{
e.OutputText=e.DateTime.ToString(“dd.MM”)+” – “+e.DateTime.AddDays(6).ToString(“dd.MM”);
e.ContinueDraw=true;
}
}
Supports answer: The answer to this is that weeks presentation is performed when drawMarker.DayOfWeek == timeLine.MidWeek, so Uli is correct. For week presentation the supplied date will need an AddDays(-3) for displaying the start of the week correctly. This was a bit unexpected in the design phase but we are keeping this behaviour so you can safely substract 3 days to get the start and add 3 days to get the end of the week (all cultures have 7 days a week right?!).
In phGantTimePackage you implement the event OnScalerStringShort and OnScalerStringLong to change the short and long intervall representation.
Also; the Gantt.DateScaler.ShowWeekNumbers=true and the Gantt.DateScaler.StartOfWeek property is an easy way to an alternative week presentation.