Custom startdate

Integrating and modifying Proof's amazing mini-calendar.
Proof Group
Proof Group
Posts: 6
Joined: Tue Jun 24, 2008 4:16 am
PostPosted: Mon Mar 16, 2009 2:44 pm
In Versions 1.0 - 1.0.2 NinjaCal's allows for either monday or sunday start days. If you need to do a different start day, replace the NinjaCal_basic and NinjaCal_triple calculation fields with the following code:

NinjaCal_Basic
Code: Select all
// focus month is centered on the first grid

Let ( [
 
        isMondayStart = 3  ;  // <- 0 = Sun, 1 = Monday, 2 = Tues...
   
      // ----------------- do not change anything below ----------------
      // our base display date
            $$__NinjaCalBaseDate =
                                     Case ( GetAsBoolean( $$__NinjaCalBaseDate ) ;
                                                $$__NinjaCalBaseDate ;
                                                Let ( $$__NinjaCalBaseDate =  Get(CurrentDate) ; $$__NinjaCalBaseDate )
                                              ) ;

    //base date components to handle multiple cal grids
           baseM = Month ( $$__NinjaCalBaseDate ) ;
           baseD = Day ($$__NinjaCalBaseDate ) ;
           baseY = Year ($$__NinjaCalBaseDate ) ;
                                       
     R = Get ( CalculationRepetitionNumber ) ;              // the current repetition, starts at "1" ;

     N = If ( Mod ( R ; 42 ) = 0 ; 42 ; Mod ( R ; 42 ) ) ;    // R normalized to 42 days for each cell in a 42 grid cal

     Moffset =   Ceiling ( R/42) - 1 ;                               // month offset for each additional cal grid set
     
     firstDateOfMo =   Date ( Month( $$__NinjaCalBaseDate ) + Moffset  ; 1 ; Year ( $$__NinjaCalBaseDate )); 
            // firstDateOfMo will always be cal date 1/mm/yyyy where mm is governed by grid offset

     dayOfWkFirstDate  =   DayOfWeek ( firstDateOfMo )  - isMondayStart ;    // tells us which week day 1/mm/yyyy is     
       startDate   =  firstDateOfMo - dayOfWkFirstDate ;
       
       dispDate =   Case (
                                 isMondayStart >= 1 ;
                                        Case ( dayOfWkFirstDate <= 0 ; startDate + N -7 ; startDate + N  ) ;
                                        startDate +N
                                  )
  ] ;

  // output
       
      Case (   
           R  ≥  1000;  Date ( baseM + Mod ( R; 1000 ) ; BaseD ; BaseY )  ; // repetitions greater than 1000 are used as grid month Displays
          dispDate
      )

 )


NinjaCal_triple

Code: Select all
// shifted left one month

Let ( [
 
        isMondayStart = 3 ;  // <<- change this value to 0 for sunday, 1 for monday, 2 for tuesday, etc.
   
      // ----------------- do not change anything below ----------------
      // our base display date
            $$__NinjaCalBaseDate =
                                     Case ( GetAsBoolean( $$__NinjaCalBaseDate ) ;
                                                $$__NinjaCalBaseDate ;
                                                Let ( $$__NinjaCalBaseDate =  Get(CurrentDate) ; $$__NinjaCalBaseDate )
                                              ) ;

    //base date components to handle multiple cal grids
           baseM = Month ( $$__NinjaCalBaseDate ) ;
           baseD = Day ($$__NinjaCalBaseDate ) ;
           baseY = Year ($$__NinjaCalBaseDate ) ;
                                       
     R = Get ( CalculationRepetitionNumber ) ;              // the current repetition, starts at "1" ;

     N = If ( Mod ( R ; 42 ) = 0 ; 42 ; Mod ( R ; 42 ) ) ;    // R normalized to 42 days for each cell in a 42 grid cal

     Moffset =   Ceiling ( R/42) - 2  ;                               // month offset shifted left one so that 2nd grid is focus
     
     firstDateOfMo =   Date ( Month( $$__NinjaCalBaseDate ) + Moffset  ; 1 ; Year ( $$__NinjaCalBaseDate )); 
            // firstDateOfMo will always be cal date 1/mm/yyyy where mm is governed by grid offset



     dayOfWkFirstDate  =   DayOfWeek ( firstDateOfMo )  - isMondayStart ;    // tells us which week day 1/mm/yyyy is     
       startDate   =  firstDateOfMo - dayOfWkFirstDate ;
       
       dispDate =   Case (
                                 isMondayStart >= 1 ;
                                        Case ( dayOfWkFirstDate <= 0 ; startDate + N -7 ; startDate + N  ) ;
                                        startDate +N
                                  )


  ] ;

  // output
       
      Case (   
           R  ≥  1000;  Date ( baseM-1 + Mod ( R; 1000 ) ; BaseD ; BaseY )  ; // repetitions greater than 1000 are used as grid month Displays
          dispDate
      )

 )
Ernest Koe
The Proof Group LLC

Return to NinjaCal

Who is online

Users browsing this forum: No registered users and 1 guest

(855) SEEDCODE
support@seedcode.com
Follow us: