Example #1
0
        /// <summary>
        /// Calculate End Date based on start date and qty
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="startDate"></param>
        /// <param name="C_UOM_ID"></param>
        /// <param name="qty"></param>
        /// <returns>end date</returns>
        public static DateTime?GetEndDate(Ctx ctx, DateTime?startDate, int C_UOM_ID, Decimal?qty)
        {
            //GregorianCalendar endDate = new GregorianCalendar();
            DateTime?endDate = new DateTime();

            //endDate.setTime(startDate);
            endDate = startDate;
            int minutes = MUOMConversion.ConvertToMinutes(ctx, C_UOM_ID, qty);

            //endDate.add(Calendar.MINUTE, minutes);
            //endDate.AddMinutes((Double)minutes);
            endDate = endDate.Value.AddMinutes(minutes);
            //DateTime retValue = new DateTime(endDate.getTimeInMillis());
            DateTime?retValue = endDate;

            //log.config( "TimeUtil.getEndDate", "Start=" + startDate
            //    + ", Qty=" + qty + ", End=" + retValue);
            return(retValue);
        }
Example #2
0
        }       //	getDayTimeSlots

        /**
         *  Create Time Slots
         */
        private void CreateTimeSlots()
        {
            //	development error
            if (_typeName == null)
            {
                throw new ArgumentNullException("ResourceTypeName not set");
            }

            List <MAssignmentSlot> list = new List <MAssignmentSlot>();

            MUOM.Get(_ctx, _C_UOM_ID);
            int minutes = MUOMConversion.ConvertToMinutes(_ctx, _C_UOM_ID, Env.ONE);

            log.Config("Minutes=" + minutes);
            //
            if (minutes > 0 && minutes < 60 * 24)
            {
                //	Set Start Time
                //            GregorianCalendar cal = new GregorianCalendar();
                //            cal.setTime(m_startDate);
                //            cal.set(Calendar.HOUR_OF_DAY, 0);
                //            cal.set(Calendar.MINUTE, 0);
                //            cal.set(Calendar.SECOND, 0);
                //            cal.set(Calendar.MILLISECOND, 0);
                DateTime cal = new DateTime(_startDate.Value.Year, _startDate.Value.Month, _startDate.Value.Day);
                //            //	we have slots - create first
                if (_slotStartTime != null)
                {
                    long start = cal.Ticks;                                // cal.getTimeInMillis();
                    cal = TimeUtil.GetDayTime(_startDate, _slotStartTime); //	set to start time
                    //                cal.set(Calendar.SECOND, 0);
                    //                cal.set(Calendar.MILLISECOND, 0);
                    list.Add(new MAssignmentSlot(start, cal.Ticks));
                }
                //            //	Set End Time
                //            GregorianCalendar calEnd = new GregorianCalendar();
                DateTime calEnd;
                if (_slotEndTime != null)
                {
                    calEnd = TimeUtil.GetDayTime(_startDate, _slotEndTime);
                    //calEnd.set(Calendar.SECOND, 0);
                    //               // calEnd.set(Calendar.MILLISECOND, 0);
                }
                else                    //	No Slot - all day
                {
                    //                calEnd.setTime(m_startDate);
                    //              calEnd.set(Calendar.HOUR_OF_DAY, 0);
                    //            calEnd.set(Calendar.MINUTE, 0);
                    //          calEnd.set(Calendar.SECOND, 0);
                    //        calEnd.set(Calendar.MILLISECOND, 0);
                    calEnd = new DateTime(_startDate.Value.Year, _startDate.Value.Month, _startDate.Value.Day, 0, 0, 0, 0);
                    calEnd = calEnd.AddDays(1);
                }
                ////System.out.println("Start=" + new Timestamp(cal.getTimeInMillis()));
                ////System.out.println("Endt=" + new Timestamp(calEnd.getTimeInMillis()));

                //            //	Set end Slot Time
                //            GregorianCalendar calEndSlot = new GregorianCalendar();
                DateTime calEndSlot = new DateTime(cal.Ticks);
                //            calEndSlot.setTime(cal.getTime());
                calEndSlot = calEndSlot.AddMinutes(minutes);

                while (cal < calEnd)
                {
                    list.Add(new MAssignmentSlot(cal.Ticks, calEndSlot.Ticks));
                    //                //	Next Slot
                    cal        = cal.AddMinutes(minutes);
                    calEndSlot = calEndSlot.AddMinutes(minutes);
                }
                //            //	create last slot
                //calEndSlot.setTime(cal.getTime());
                calEndSlot = new DateTime(cal.Year, cal.Month, cal.Day, 0, 0, 0, 0);
                //            calEndSlot.set(Calendar.HOUR_OF_DAY, 0);
                //            calEndSlot.set(Calendar.MINUTE, 0);
                //            calEndSlot.set(Calendar.SECOND, 0);
                //            calEndSlot.set(Calendar.MILLISECOND, 0);
                //            calEndSlot.add(Calendar.DAY_OF_YEAR, 1);	//	00:00 next day
                calEndSlot = calEndSlot.AddDays(1);
                list.Add(new MAssignmentSlot(cal.Ticks, calEndSlot.Ticks));
            }

            else        //	Day, ....
            {
                list.Add(new MAssignmentSlot(TimeUtil.GetDay(_startDate), TimeUtil.GetNextDay(_startDate)));
            }

            //
            _timeSlots = new MAssignmentSlot[list.Count];
            _timeSlots = list.ToArray();
        }       //	createTimeSlots