private String getLocalizedDate(int year, int month, int day, bool extendLastDate) { //// we use the default Locale/TZ since LuceneTestCase randomizes it //DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); //Calendar calendar = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault()); //calendar.set(year, month, day); //if (extendLastDate) //{ // calendar.set(Calendar.HOUR_OF_DAY, 23); // calendar.set(Calendar.MINUTE, 59); // calendar.set(Calendar.SECOND, 59); // calendar.set(Calendar.MILLISECOND, 999); //} //return df.format(calendar.getTime()); var calendar = new GregorianCalendar(GregorianCalendarTypes.Localized); DateTime lastDate = calendar.ToDateTime(year, month, day, 0, 0, 0, 0); lastDate = TimeZoneInfo.ConvertTime(lastDate, TimeZoneInfo.Local); if (extendLastDate) { lastDate = calendar.AddHours(lastDate, 23); lastDate = calendar.AddMinutes(lastDate, 59); lastDate = calendar.AddSeconds(lastDate, 59); lastDate = calendar.AddMilliseconds(lastDate, 999); } return(lastDate.ToString("d")); //.ToShortDateString(); }
}//getStartDateRange // Sets the dates for the report. The date range is midnight Friday // of the previous week to 1 second before midnight of the week // within which the given date falls, inclusive. private void setDates(DateTime givenDate) { Calendar calendar = new GregorianCalendar(); //adjust time to 00:00:00 -- dates entered by manager already have //time as 00:00:00, but when testing the accounting procedure //the time is the current system time givenDate = calendar.AddHours(givenDate, 0); givenDate = calendar.AddMinutes(givenDate, 0); givenDate = calendar.AddSeconds(givenDate, 0); givenDate = calendar.AddMilliseconds(givenDate, 0); // Set end date to the Friday of the week in which it falls //i.e a Saturday is set to the preceding Friday //Sunday to Thursday is set to the following Friday givenDate = givenDate.AddDays(-(int)givenDate.DayOfWeek).AddDays(5); endDate = givenDate; //Use Saturday 00:00:00 am as end of range (exclusive) givenDate = givenDate.AddDays(-(int)givenDate.DayOfWeek).AddDays(6); endDateRange = givenDate; //Use the previous Friday 12:59:59 pm as //the beginning of range (exclusive) givenDate = givenDate.AddDays(-(int)givenDate.DayOfWeek).AddDays(-5); givenDate = calendar.AddSeconds(givenDate, -1); startDateRange = givenDate; }//setDates
private long GetNextPoint(ref DateTime t, int unit, int unitSteps) { switch (unit) { case 0: t = gc.AddSeconds(t, unitSteps); break; case 1: t = gc.AddMinutes(t, unitSteps); break; case 2: t = gc.AddHours(t, unitSteps); break; case 3: t = gc.AddDays(t, unitSteps); break; case 4: t = gc.AddWeeks(t, unitSteps); break; case 5: t = gc.AddMonths(t, unitSteps); break; case 6: t = gc.AddYears(t, unitSteps); break; default: break; } return(Util.TicksToMillis(t.Ticks)); }
public void DrawX(Graphics g, AdvancedRect area, AdvancedRect plotArea) { drawArea = area; //using (Brush br = new SolidBrush(Color.Green)) // g.FillRectangle(br, area.Rect); GraphicsState _s = g.Save(); using (Brush br = labelFont.CreateBrush()) using (Font f = labelFont.CreateFont()) using (Font f2 = smallLabelFont.CreateFont()) using (Pen p = tickPen.CreatePen()) using (Pen pgrid = gridlinePen.CreatePen()) using (Pen pminor = minorTickPen.CreatePen()) { CalculateNext nextMajor = GetNextMajorFunction(); // Same dealy-o, but for minor ticks / labels. CalculateNext nextMinor = null; if (axisType == AxisType.MonthsHorizontalWithDailyTicks || axisType == AxisType.MonthsHorizontalWithDailyLabels) { nextMinor = delegate(DateTime dt) { return(cal.AddDays(dt, 1)); } } ; else if (axisType == AxisType.DailyWithHourlyTicks || axisType == AxisType.DailyWithHourlyLabels) { nextMinor = delegate(DateTime dt) { return(cal.AddHours(dt, 1)); } } ; else if (axisType == AxisType.Quarters) { nextMinor = delegate(DateTime dt) { return(cal.AddMonths(dt, 1)); } } ; // Determine major label format -- {0} is the major label v, // {1} is the quarter string majorLabel = null; if (axisType == AxisType.Quarters) { majorLabel = "Q{1} {0:\\'yy}"; } else if (axisType == AxisType.DailyWithHourlyTicks || axisType == AxisType.DailyWithHourlyLabels) { majorLabel = "{0:MMM %d \\'yy}"; } else { majorLabel = "{0:MMM \\'yy}"; } // Determine minor label format: string minorLabel = null; if (axisType == AxisType.MonthsHorizontalWithDailyLabels) { minorLabel = "{0:%d}"; } else if (axisType == AxisType.DailyWithHourlyLabels) { minorLabel = "{0:%h%t}"; } // Add some extra spacing if putting minor labels in. float minorLabelSpacing = 0; if (nextMinor != null && minorLabel != null) { minorLabelSpacing = 1f / 16; } // StringFormat for drawing major labels: StringFormat majorForm = new StringFormat(); if (axisType == AxisType.MonthsVertical || axisType == AxisType.Quarters) { majorForm.FormatFlags = StringFormatFlags.DirectionVertical; } // Determine first major label value. DateTime dtLeft; if (axisType == AxisType.Quarters) { // set v to beginning of quarter which ScaleMinimum is in dtLeft = new DateTime(ScaleMinimum.Year, (((ScaleMinimum.Month - 1) / 3) * 3) + 1, 1); } else if (axisType == AxisType.DailyWithHourlyTicks || axisType == AxisType.DailyWithHourlyLabels) { // set v to beginning of day dtLeft = new DateTime(ScaleMinimum.Year, ScaleMinimum.Month, ScaleMinimum.Day); } else { // set v to beginning of month dtLeft = new DateTime(ScaleMinimum.Year, ScaleMinimum.Month, 1); } for (int i = 0; i < calculateNumLabels(); i++) { float xLeft = DataToCoordinate(dtLeft, area); xLeft = Math.Max(xLeft, area.TopLeft.X); if (xLeft > area.BottomRight.X) { break; } DateTime dtRight = nextMajor(dtLeft); float xRight = DataToCoordinate(dtRight, area); xRight = Math.Min(xRight, area.BottomRight.X); // Major ticks & gridlines: g.DrawLine(p, xLeft, area.TopLeft.Y, xLeft, area.TopLeft.Y + tickLength); if (gridlinesEnabled && xLeft > area.TopLeft.X && xLeft < area.BottomRight.X) { g.DrawLine(pgrid, xLeft, plotArea.TopLeft.Y, xLeft, plotArea.BottomRight.Y); } // Minor ticks: if (nextMinor != null) { DateTime dtMinorLeft = nextMinor(dtLeft); while (dtMinorLeft < dtRight) { float xMinorLeft = DataToCoordinate(dtMinorLeft, area); if (xMinorLeft > area.TopLeft.X && xMinorLeft < area.BottomRight.X) { g.DrawLine(pminor, xMinorLeft, area.TopLeft.Y, xMinorLeft, area.TopLeft.Y + minorTickLength); } dtMinorLeft = nextMinor(dtMinorLeft); } } if (minorLabel != null && nextMinor != null) { DateTime dtMinorLeft = dtLeft; while (dtMinorLeft < dtRight) { DateTime dtMinorRight = nextMinor(dtMinorLeft); float xMinorLeft = DataToCoordinate(dtMinorLeft, area); float xMinorRight = DataToCoordinate(dtMinorRight, area); if (xMinorLeft >= area.TopLeft.X && xMinorRight <= area.BottomRight.X) { string dtxt = String.Format(minorLabel, dtMinorLeft); SizeF dsz = g.MeasureString(dtxt, f2); float xlabel = ((xMinorLeft + xMinorRight) / 2) - (dsz.Width / 2); if (xlabel > area.TopLeft.X && (xlabel + dsz.Width) < area.BottomRight.X) { g.DrawString(dtxt, f2, br, ((xMinorLeft + xMinorRight) / 2) - (dsz.Width / 2), area.TopLeft.Y); } } dtMinorLeft = dtMinorRight; } } // Draw major label: string txt = String.Format(majorLabel, dtLeft, (dtLeft.Month / 3) + 1); SizeF sz = g.MeasureString(txt, f, 100, majorForm); float draw_x = ((xLeft + xRight) / 2) - (sz.Width / 2); if (draw_x > area.TopLeft.X && (draw_x + sz.Width) < area.BottomRight.X) { g.DrawString(txt, f, br, ((xLeft + xRight) / 2) - (sz.Width / 2), area.TopLeft.Y + tickLength + minorLabelSpacing, majorForm); } dtLeft = dtRight; } // one final tick to signify end of last visible month float xL = DataToCoordinate(dtLeft, area); if (xL < area.BottomRight.X) { g.DrawLine(p, xL, area.TopLeft.Y, xL, area.TopLeft.Y + tickLength); if (gridlinesEnabled) { g.DrawLine(pgrid, xL, plotArea.TopLeft.Y, xL, plotArea.BottomRight.Y); } } } g.Restore(_s); }