Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        }//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