!-------------------------------------------------
!  DATElib Module
!-------------------------------------------------
module datelib
  use dcl_common
  
contains
!----------------------------------------------------------------
    function DclGetDate()
      type(dcl_date) :: DclGetDate
      call dateq3(DclGetDate%year,DclGetDate%month,DclGetDate%day) 
    end function
!----------------------------------------------------------------
    function DclAddDate(date, n) 
      type(dcl_date) :: DclAddDate
      type(dcl_date), intent(in) :: date
      integer,        intent(in) :: n 
      call datef3(n, date%year,      date%month,      date%day, &
            &        DclAddDate%year,DclAddDate%month,DclAddDate%day)
    end function
!----------------------------------------------------------------
    function DclDiffDate(date1, date2)
      integer                    :: DclDiffDate
      type(dcl_date), intent(in) :: date1, date2
      
      DclDiffDate = ndate3(date1%year, date1%month, date1%day, &
                  &        date2%year, date2%month, date2%day)
    end function
!----------------------------------------------------------------
    subroutine DclFormatDate(cform,date)
      type(dcl_date),   intent(in)    :: date
      character(len=*), intent(inout) :: cform    !日付のフォーマット
      call datec3(cform,date%year,date%month,date%day)
    end subroutine
!----------------------------------------------------------------
    function DclDayOfWeek(date)
      integer ::  DclDayOfWeek
      type(dcl_date),   intent(in)    :: date
      DclDayOfWeek = iweek3(date%year,date%month,date%day)  
    end function
!----------------------------------------------------------------
    function DclLengthOfMonth(iy,im)  !iy年im月は何日あるかを返す．
      integer,   intent(in) :: iy                 !年
      integer,   intent(in) :: im                 !月
      integer               :: DclLengthOfMonth 
      DclLengthOfMonth = ndmon(iy,im) 
    end function
!----------------------------------------------------------------
    function DclLengthOfYear(iy)                !iy年は何日あるかを返す．
      integer, intent(in) :: iy                 !年
      integer             :: DclLengthOfYear    !指定した年の日数を与える関数値
      DclLengthOfYear = ndyear(iy)  
    end function
!----------------------------------------------------------------
end module
