home *** CD-ROM | disk | FTP | other *** search
- /*
- Function: GETDATE()
- System: GRUMPFISH LIBRARY
- Author: Greg Lief
- Copyright (c) 1988-90, Greg Lief
- Clipper 5.01 version
- Compile instructions: clipper getdate /n/w/a
-
- Procs & Funcs: GETDATE()
-
- Calls: CALENDBOX() (function in $CALENDA.PRG)
- : NEXTMONTH() (function in $CALENDA.PRG)
- */
-
- //───── begin preprocessor directives
-
- #include "grump.ch"
- #include "inkey.ch"
- #define CURRENTYEAR substr(dtos(mdate), 1, 4)
- #define CURRENTDAY substr(dtos(mdate), 7)
-
- //───── end preprocessor directives
-
- function getdate(mdate, mtop, mleft, maincolor)
- local row, tdate, lastday, newrow, newcol, tempdate, datecoords, ;
- xx, redraw, olddelete := set(_SET_DELETED, .T.), keypress
-
- //───── use system date as starting date if not passed as parameter
- //───── determine screen position and color if not passed as parameters
- mdate := if(empty(mdate), date(), mdate)
- default mtop to 6
- default mleft to 28
- default maincolor to ColorSet(C_CALENDAR, .T.)
-
- GFSaveEnv( { mtop, mleft, mtop + 13, mleft + 23 }, 0 ) // shut off cursor
- datecoords := CalendBox(.f., mtop, mleft, mdate, maincolor, .t.)
- //───── commence main keypress loop
- do while .t.
- redraw := .f.
- keypress := ginkey(0)
- tdate := mdate && store highlighted date
- newrow := CURRENTDAY_ROW
- newcol := CURRENTDAY_COL
- do case
-
- case keypress == K_DOWN .or. keypress == K_UP // forward/backward one week
- mdate += if(keypress = 24, 7, -7)
- newrow += if(keypress = 24, 1, -1)
-
- case keypress == K_LEFT // go back one day
- mdate--
- //───── did we just go from sunday to saturday??
- newrow := if(dow(mdate) = 7, CURRENTDAY_ROW - 1, CURRENTDAY_ROW)
- newcol := if(dow(mdate) = 7, mleft + 19, CURRENTDAY_COL - 3)
-
- case keypress == K_RIGHT // go forward one day
- mdate++
- //───── did we just go from saturday to sunday??
- newrow := if(dow(mdate) = 1, CURRENTDAY_ROW + 1, CURRENTDAY_ROW)
- newcol := if(dow(mdate) = 1, mleft + 1, CURRENTDAY_COL + 3)
-
- case keypress == K_PGUP // go back one month
- if month(mdate) == 1 // going to December of previous year
- mdate := stod( str(val(CURRENTYEAR)-1, 4) + '12' + CURRENTDAY)
- else
- //───── check for validity of current date in previous month
- //───── i.e., cannot go from march 31 to february 31, etcetera
- tempdate := ctod('')
- do while empty(tempdate)
- tempdate := stod(CURRENTYEAR + if(month(mdate) < 11, '0', '') + ;
- ltrim(str(month(mdate) - 1)) + CURRENTDAY)
- mdate--
- enddo
- mdate := tempdate
- endif
-
- case keypress == K_PGDN // go forward one month
- mdate := NextMonth(mdate)
-
- case keypress == K_HOME // go to first day
- newrow := FIRSTDAY_ROW
- newcol := FIRSTDAY_COL
- mdate := stod(substr(dtos(mdate), 1, 6) + '01')
-
- case keypress == K_END // go to last day
- newrow := LASTDAY_ROW
- newcol := LASTDAY_COL
- mdate := stod(substr(dtos(mdate), 1, 6) + str(LASTDAY_NUMBER, 2))
-
- case keypress == K_ENTER .or. keypress == K_ESC // enter or esc - quit
- exit
-
- otherwise // any other keystroke
- loop
-
- endcase
- //───── if we changed months, redraw calendar
- if month(tdate) != month(mdate) .or. redraw
- datecoords := CalendBox(.f., mtop, mleft, mdate, maincolor)
- else
- @ CURRENTDAY_ROW, CURRENTDAY_COL ssay str(day(tdate),2) ;
- color '+' + maincolor
- @ newrow, newcol ssay str(day(mdate), 2) color '*+' + maincolor
- //───── store new row/column coordinates for highlighted date
- CURRENTDAY_ROW := newrow
- CURRENTDAY_COL := newcol
- endif
- enddo
-
- GFRestEnv()
- return if(keypress == K_ENTER, mdate, ctod(""))
-
- * end function GetDate()
- *--------------------------------------------------------------------*
-
- * eof getdate.prg
-