Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Help with showing dates on a calendar(Script)

Hi Guys

I have a form
On the form are 2 Date/Time fields

From and To

Also I have field WorkDays which is number field and TotalDays which is Date?Time with allw multi values
I have a view course calendar

I would like to show on the calendar view all the days a course runs
If it runs 1 day then show one day if it is longer then indicate each day that it runs
I know this involves subtracting the From field from the To field, not sure how to do that in script, I have tried a couple of things and it is not working out

I need to calculate this at the time the document is created so maybe call this function at the quesry save or postrecalc?


Here is the code in the globals that I have been trying to get to work

Sub CalculateWorkDays(workdays As Double)
'*******************************************************************************************
' Purpose : This subroutine is to calculate no. of working days which will be
' taken for course.  It also fills the field TotalDaysf so that it can populate the
' calendar views properly.
'  
'      Added & Modified to work with Session form and Course Calendar view in DIPR
'    db from LTVS db
      
'*******************************************************************************************    
      
      Dim session As NotesSession
      Dim ws As NotesUIWorkspace
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim dateTime As NotesDateTime
      
      Dim CompareDate As Variant
      Dim TotalDays As Variant
      Dim nonworkdays As Double
      Dim FromIsLessThanTo As Variant    
      Dim i As Double
      
      Set session = New NotesSession
      Set ws = New NotesUIWorkspace
      Set db = session.CurrentDatabase
      Set uidoc = ws.CurrentDocument
      Set doc = uidoc.document
      workdays = 1
      nonworkdays = 0
      
      If doc.SessionDate(0) <> "" And doc.SessionDateEndDT(0) <> "" And (doc.SessionDate(0) <= doc.SessionDateEndDT(0)) Then
            FromIsLessThanTo = True            
            CompareDate = doc.SessionDate(0)
            TotalDays = 1
            
            While FromIsLessThanTo
                  If (CompareDate =>1 And CompareDate <= 5) Then
                        workdays  =workdays + 1          
                        
' Apr 2003 =====                        
'                        Set dateTime = New NotesDateTime (CompareDate + " 12:00:00 AM")  
                        Set dateTime = New NotesDateTime (CompareDate + " 8:00:00 AM")  
'==============                        
                        TotalDays = TotalDays + ";" + dateTime.LocalTime              
                  Else
                        nonworkdays = nonworkdays + 1
                  End If
                  CompareDate = CompareDate + 1
                  If CompareDate > doc.SessionDate(0) Then
                        FromIsLessThanTo = False
                  End If
            Wend
      End If
      doc.workdays = workdays
      doc.nonworkdays = nonworkdays          
      doc.TotalDays =  workdays
      
End Sub
0
imjamesw
Asked:
imjamesw
  • 3
  • 3
  • 2
2 Solutions
 
Sjef BosmanGroupware ConsultantCommented:
Would this be something for you?
http:Q_20920029.html "Calculating time interval between 2 date and time (excluding non-working days)"
0
 
imjameswAuthor Commented:
One thing I sshould add is that this is straight work week stuff, no calculations for weekends or holidays

0
 
qwaleteeCommented:
Didn't we go through code exactly like this about a year ago?

If we ignore the need to exclude weekends and holidays, it is real simple:
    allDaysInRange := @TextToTime(@Explode(@TextToTime(@Text(From) + " - "+ @Text(To))))

If you want to exclude weekends:
    textDaysInRange := @Explode(@TextToTime(@Text(From) + " - "+ @Text(To)));
    dateDaysInRange := @TextToTime(textDaysInRange);
    textDaysOfWeek := @Text(@Weekday(dateDaysInRange));
    marker := @Char(250);
    markWeekDays := @Replace(textDaysOfWeek; "2":"3":"4":"5":"6"; marker);
    textWorkDays := @Right(markWeekDays + textDaysInRange; marker);
    @TextToTime(textWorkDays);

If you want to exclude holidays, you need a list of holidays, and you can easily do a repace between the textWorkDays and the @TextToTime at the end.

If you need a count, just get @Elements of the result.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
imjameswAuthor Commented:
Yes we did, however I am trying to keep with the company standard and do it in script
Using what I have included below works ,I call it from a Postrecalc
Thanx abunch

James

Sub CalculateWorkDays(workdays As Double)
'*******************************************************************************************
' Purpose : This subroutine is to calculate no. of working days which will be
' taken for course.  It also fills the field TotalDaysf so that it can populate the
' calendar views properly.
'  
'      Added & Modified to work with Session form and Course Calendar view in DIPR
'    db from LTVS db
      
'*******************************************************************************************    
      
      Dim session As NotesSession
      Dim ws As NotesUIWorkspace
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim dateTime As NotesDateTime
      
      Dim CompareDate As Variant
      Dim TotalDays As Variant
      Dim nonworkdays As Double
      Dim FromIsLessThanTo As Variant    
      Dim i As Double
      
      Set session = New NotesSession
      Set ws = New NotesUIWorkspace
      Set db = session.CurrentDatabase
      Set uidoc = ws.CurrentDocument
      Set doc = uidoc.document
      workdays = 0
      nonworkdays = 0
      
      If doc.SessionDate(0) <> "" And doc.SessionDateEndDT(0) <> "" And (doc.SessionDate(0) <= doc.SessionDateEndDT(0)) Then
            FromIsLessThanTo = True            
            CompareDate = doc.SessionDate(0)
            TotalDays = ""
            
            While FromIsLessThanTo
                  If (doc.SessionDate(0) < doc.SessionDateEndDT(0)) Then
                        workdays  = workdays + doc.SessionDateEndDT(0) - doc.SessionDate(0)
                  'TotalDays = TotalDays + ";" + CompareDate    
' Apr 2003 =====                        
'                        Set dateTime = New NotesDateTime (CompareDate + " 12:00:00 AM")  
                        Set dateTime = New NotesDateTime (CompareDate + " 8:00:00 AM")  
'==============                        
                        TotalDays = TotalDays + ";" + dateTime.LocalTime              
                  Else
                        nonworkdays = nonworkdays + 1
                  End If
                  CompareDate = CompareDate + 1
                  If CompareDate > doc.SessionDateEndDT(0) Then
                        FromIsLessThanTo = False
                  End If
            Wend
      End If
      doc.workdays = workdays
      doc.nonworkdays = nonworkdays          
      doc.TotalDays =  TotalDays
      
End Sub
0
 
Sjef BosmanGroupware ConsultantCommented:
So the Formula-stuff works? Then rebuild it in LS.

Otherwise, please define
- input
- process
- output
0
 
qwaleteeCommented:
I hate retarded company standards that are written by either people with outside egos or who do not understand hhow the product works.

There's one place where the first developer had done a lot of stuff over the years, and had some good, solid, 50%-formula, 50%-script solutions. Junior guy comes in, learns a little bit about Nootes by taking the cert classes, and is immediately coding everything in script and complaining thathe cant understand teh "crazy templates" designed by the senior guy.

Couple of months later, senor guy gets a job offer and walks.  The junior guy is the only guy, and whiel they are looking for a senior replacement, the junior guy sugests they create a standard forbidding formula on forms and in agents.  Ties the hands of the new senior guy with this.  Suddenly, everything takes twice as long, crashes more often, but, hey, a standard is a standard!
0
 
Sjef BosmanGroupware ConsultantCommented:
See the third statement in my EE-profile :)
0
 
imjameswAuthor Commented:
You are so right Qwalatee
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now