def findXthDayOfMonth(self, date, day_name, pos):
        """
        Return: date of the Xth day (day_name) of given date month.
        date: DateTime
        day_name: string
        pos: int
        return: DateTime (%y/%m/%d)
        """
        month_number = date.month()
        ref_date = DateTime('%s/%s/01' % (date.year(), date.month()))
        while pos >= 0:
            # decrease pos when the day name is found
            if ref_date.Day() == day_name:
                pos = pos - 1

            #verify that we do not change the month
            if ref_date.month() != month_number:
                return 0

            #cool, we find the day
            if ref_date.Day() == day_name and pos == 0:
                return ref_date

            ref_date = ref_date + 1

        return 0
Esempio n. 2
0
 def testEDTTimezone(self):
     """Should be able to parse EDT timezones"""
     dt = DateTime("Mon, 28 Jun 2010 10:12:25 EDT")
     self.assertEqual(dt.Day(), 'Monday')
     self.assertEqual(dt.day(), 28)
     self.assertEqual(dt.Month(), 'June')
     self.assertEqual(dt.timezone(), 'GMT-0400')
Esempio n. 3
0
 def testEDTTimezone(self):
     # should be able to parse EDT timezones:  see lp:599856.
     dt = DateTime("Mon, 28 Jun 2010 10:12:25 EDT")
     self.assertEqual(dt.Day(), 'Monday')
     self.assertEqual(dt.day(), 28)
     self.assertEqual(dt.Month(), 'June')
     self.assertEqual(dt.timezone(), 'GMT-4')
Esempio n. 4
0
def get_date(date):
	date = str(date) 

	if(len(date)==0):
		return "Not Specified"
	x = DateTime(date)
	new_date = ""
	new_date += x.Day() + '  ' + str(x.day()) + '  ' + x.Month()  + '  ' + str(x.year())
	# print("new date is : " + str(new_date))
	return new_date
    def update(self):
        context = aq_inner(self.context)
        ptool = self.tools().properties()
        hours_per_day = ptool.xm_properties.getProperty('hours_per_day')
        request = self.request
        weeklist = []
        # Start at first day of the week.  Note: with the
        # DateTime.week() method Monday is considered the first day,
        # even though DateTime.dow() says Sunday is day zero.  To make
        # things worse, if say Sunday is 1 October, we want to start
        # with the week of Monday 25 September.

        # Go to the beginning of the week that has the first day of
        # this month.  How many days do we have to subtract for that?
        offset = self.startDate.dow() - 1
        if offset < 0:
            # Only happens for Sunday
            offset += 7

        if offset == 0:
            date = self.startDate
            year, month = self.year, self.month
        else:
            year, month = getPrevYearMonth(self.year, self.month)
            last_day = getEndOfMonth(year, month).day()
            date = DateTime(year, month, last_day - offset + 1)
        daynumber = date.day()
        # Assemble info for at most one month:
        ploneview = context.restrictedTraverse('@@plone')
        month_billable = 0.0
        month_worked_days = 0

        # When comparing dates, make sure December of previous year is
        # less than January of this year.
        while date.month() + 12 * date.year() <= self.month + 12 * self.year:
            weekinfo = dict(
                week_number=date.week(),
                week_start=ploneview.toLocalizedTime(date),
            )
            # Start the week cleanly
            day_of_week = 0
            daylist = []
            week_total = 0.0
            week_strict_total = 0.0
            days_bookings = DayBookingOverview(context,
                                               request,
                                               memberid=self.memberid)
            week_billable = 0.0
            week_worked_days = 0
            # Strict billable means: only count days of this week that
            # are really in this month.
            week_strict_billable = 0.0
            week_strict_worked_days = 0
            while day_of_week < 7:
                day_total = days_bookings.raw_total(date=date)
                day_billable = days_bookings.raw_billable(date=date)
                ui_class = 'greyed'
                if day_total > 0:
                    # Update week stats
                    week_total += day_total
                    if day_total != 0:
                        # Only add the billable hours to the week when
                        # some work (billable or not) has been done
                        # today.
                        week_billable += day_billable
                        week_worked_days += 1
                    if date.month() == self.startDate.month():
                        # Update strict stats
                        week_strict_total += day_total
                        week_strict_billable += day_billable
                        week_strict_worked_days += 1
                        # Update month stats
                        self.raw_total += day_total
                        if day_total != 0:
                            # Only add the billable hours to the month
                            # when some work (billable or not) has
                            # been done today.
                            month_billable += day_billable
                            month_worked_days += 1
                        ui_class = 'good'
                    else:
                        ui_class = 'greyed'
                    daylist.append(
                        dict(total=formatTime(day_total),
                             day_of_week=date.Day(),
                             style=ui_class))
                else:
                    daylist.append(
                        dict(total=None,
                             day_of_week=date.Day(),
                             style=ui_class))
                day_of_week += 1
                daynumber += 1
                try:
                    # We used to simply do date + 1, but that gave
                    # problems with Daylight Savings Time.
                    date = DateTime(year, month, daynumber)
                except DateTime.DateError:
                    # End of month reached, so go to the next.
                    daynumber = 1
                    year, month = getNextYearMonth(year, month)
                    try:
                        date = DateTime(year, month, daynumber)
                    except DateTime.DateError:
                        # This Should Not Happen (tm)
                        break

            # Add the info to the dict for this week
            weekinfo['days'] = daylist
            weekinfo['week_total'] = formatTime(week_total)
            weekinfo['week_strict_total'] = formatTime(week_strict_total)
            # Normal week stats
            if week_worked_days:
                norm = week_worked_days * hours_per_day
                week_perc_billable = 100.0 * week_billable / norm
            else:
                week_perc_billable = 0.0
            fmt_perc_billable = "%0.1f %%" % week_perc_billable
            # Strict week stats
            if week_strict_worked_days:
                norm = week_strict_worked_days * hours_per_day
                week_strict_perc_billable = 100.0 * week_strict_billable / norm
            else:
                week_strict_perc_billable = 0.0
            fmt_strict_perc_billable = "%0.1f %%" % week_strict_perc_billable
            weekinfo['total_style'] = weekinfo['perc_style'] = 'greyed'
            if date < DateTime():
                weekinfo['total_style'] = weekinfo['perc_style'] = 'good'
                if week_total < 40.0:
                    weekinfo['total_style'] = 'not-enough'
                if week_perc_billable < 50:
                    weekinfo['perc_style'] = 'not-enough'
            weekinfo['perc_billable'] = fmt_perc_billable
            weekinfo['strict_perc_billable'] = fmt_strict_perc_billable
            self.bookinglist.append(weekinfo)

        if month_worked_days > 0:
            norm = month_worked_days * hours_per_day
            self.perc_billable = 100.0 * month_billable / norm