home *** CD-ROM | disk | FTP | other *** search
- /*
- Program: CALENDAR.PRG
- System: GRUMPFISH LIBRARY
- Author: Greg Lief
- Copyright (c) 1988-90, Greg Lief
- Clipper 5.0 Version
- Compile instructions: clipper calendar /n/w/a
-
- Procs & Fncts: CALENDBOX()
- : NEXTMONTH()
-
- NOT FOR USE AS STAND-ALONE!! CALLED BY GETDATE() and POPDATE
- */
-
- /*
- Function: CALENDBOX
-
- Called by: POPDATE (procedure in POPDATE.PRG)
- GETDATE() (function in GETDATE.PRG)
-
- Notes: Returns an array of row/col coordinates for the first,
- last, current, and system dates
- */
-
- //───── begin preprocessor directives
-
- #include "grump.ch"
-
- //───── end preprocessor directives
-
- function calendbox(usingappts, ntop, nleft, curr_date, maincolor, firstloop)
- static calendscrn
- local hasappts, datecoords[10], gotlastday, datehead, tdate, tmonth, row := 5
- default firstloop to .f.
- if firstloop
- ColorSet(maincolor)
- shadowbox(ntop, nleft, ntop+12, nleft+21, 1)
- @ ntop + 3, nleft + 1 ssay "Su Mo Tu We Th Fr Sa"
- @ ntop + 1, nleft + 21 ssay "║"
- @ ntop + 2, nleft ssay "╠" + replicate("═",20) + "╣"
- @ ntop + 4, nleft ssay "╠" + replicate("═",20) + "╣"
- @ ntop + 12, nleft ssay "╚" + replicate("═",20) + "╝"
- calendscrn := savescreen(ntop, nleft, ntop+13, nleft+23)
- else
- restscreen(ntop, nleft, ntop+13, nleft+23, calendscrn)
- endif
- setcolor('+' + maincolor)
- datehead := gfmonth(curr_date) + ' ' + str(year(curr_date), 4)
- if len(datehead) < 14
- datehead := space((14 - len(datehead)) / 2) + datehead + ;
- space((14 - len(datehead)) / 2 + 1)
- endif
- @ ntop + 1, nleft + 4 ssay datehead
- tdate := curr_date
- tdate := stod(substr(dtos(tdate), 1, 6) + '01') && 1st day of month
- tmonth := month(tdate)
- gotlastday := .f. // flag for storing coordinates of last day of month
- CURRENTAPPTS := .f.
- do while .t.
- hasappts := .f. // flag for whether a date should be shown in inverse
- // test for new week
- if (day(tdate) > 1 .or. month(tdate) != tmonth) .and. dow(tdate) = 1
- row++
- endif
- if row > 11
- exit
- endif
- // no need to seek for appointments for current date unless we are
- // using the appointment tracker
- if usingappts
- seek dtos(tdate)
- if found()
- hasappts := .t.
- // set flag true if this date is the current date
- // so that we know to display its appts in draw_appts
- CURRENTAPPTS := if(tdate = curr_date, .t., CURRENTAPPTS)
- endif
- endif
- do case
- case usingappts .and. hasappts
- setcolor(if(tdate = curr_date, '*n/w', 'i'))
- case month(tdate) = month(curr_date)
- setcolor(if(tdate = curr_date, '*', '') + '+' + maincolor)
- otherwise
- ColorSet(maincolor)
- endcase
- @ ntop+row, nleft + (dow(tdate) - 1) * 3 + 1 ssay str(day(tdate), 2)
- do case
- // first day of month
- case day(tdate) = 1 .and. month(tdate) = tmonth
- FIRSTDAY_ROW := row()
- FIRSTDAY_COL := col()-2
- * last day of month
- case month(tdate + 1) != tmonth .and. ! gotlastday
- LASTDAY_ROW := row()
- LASTDAY_COL := col()-2
- LASTDAY_NUMBER := day(tdate)
- gotlastday := .t.
- endcase
- // current day
- if tdate = curr_date
- CURRENTDAY_ROW := row()
- CURRENTDAY_COL := col()-2
- endif
- // system date
- if tdate = date()
- SYSTEMDATE_ROW := row()
- SYSTEMDATE_COL := col()-2
- endif
- tdate++ // increment date counter
- enddo
- ColorSet(maincolor)
- return datecoords
-
- * end function CalendBox()
- *--------------------------------------------------------------------*
-
-
- /*
- Function: NEXTMONTH()
-
- Called by: GETDATE()
- : POPDATE (procedure in POPDATE.PRG)
- : RECURRING (procedure in POPDATE.PRG)
- */
- function nextmonth(origdate)
- //───── check for validity of date when skipping forward one month
- //───── i.e., cannot go from march 31 to april 31, etcetera
- local ret_val
- ret_val := ctod('')
- if month(origdate) = 12 // going to January of next year
- ret_val := stod(str(val(substr(dtos(origdate), 1, 4)) + 1, 4) + '01' + ;
- substr(dtos(origdate), 7))
- else
- do while empty(ret_val)
- ret_val := stod(substr(dtos(origdate), 1, 4) + ;
- if(month(origdate) < 9, '0', '') + ;
- ltrim(str(month(origdate) + 1)) + substr(dtos(origdate), 7))
- origdate--
- enddo
- endif
- return (ret_val)
-
- * end function NextMonth()
- *--------------------------------------------------------------------*
-
- * eof calendar.prg
-