設為首頁收藏本站

艾歐踢論壇

 找回密碼
 立即註冊

QQ登錄

只需一步,快速開始

搜索
熱搜: 活動 交友 discuz
查看: 923|回復: 0
打印 上一主題 下一主題

datetime.4gl

[複製鏈接]
跳轉到指定樓層
樓主
發表於 2016-6-14 23:19:51 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
datetime.4gl
  1. {***********************************************************************
  2.   datetime
  3.   This module contains functions which allow datetime variables to be
  4.   manipulated in various ways.

  5.   This module contains the following functions:
  6.                         Date_Plus_Time
  7.                         Month_Integer_to_String
  8.                         Max_Day_of_Month
  9.                         End_of_Next_Month
  10.                         First_Day_of_Month
  11.                         Last_Day_of_Month
  12.                         Add_Month
  13.                         File_Date_Stamp
  14.                         File_Time_Stamp

  15.   Most recent change:        Cathy Kipp        March 5, 1993
  16. ***********************************************************************}


  17. {***********************************************************************
  18.   Date_Plus_Time
  19.   This function adds a datetime variable year to day to a datetime
  20.   variable hour to minute.

  21.   Input:        date_datetime                datetime year to day
  22.                 time_datetime                datetime hour to minute

  23.   Output:        total_datetime                datetime year to minute
  24. ***********************************************************************}
  25. function Date_Plus_Time (date_datetime, time_datetime)
  26.   define date_datetime                datetime year to day,
  27.          time_datetime                datetime hour to minute,
  28.          total_datetime                datetime year to minute,
  29.          date_char                char (10),
  30.          time_char                char (5),
  31.          datetime_char                char (16)

  32.   whenever error continue

  33.   { Convert date and time inputs to character inputs }
  34.   let date_char = date_datetime
  35.   let time_char = time_datetime

  36.   { Format new datetime field }
  37.   let datetime_char = date_char clipped, " ", time_char clipped

  38.   { Assign datetime value to datetime variable }
  39.   let total_datetime = datetime_char clipped

  40.   return total_datetime
  41. end function  { Date_Plus_Time }


  42. {***********************************************************************
  43.   Month_Integer_to_String

  44.     Input:  month_num                small integer from 1 to 12

  45.     Output: month_name                char (10), name of month
  46. ***********************************************************************}
  47. function Month_Integer_to_String (month_num)
  48.   define month_num        smallint
  49.   define month_name        char (10)

  50.   case (month_num)
  51.     when 1   let month_name = "January"
  52.     when 2   let month_name = "February"
  53.     when 3   let month_name = "March"
  54.     when 4   let month_name = "April"
  55.     when 5   let month_name = "May"
  56.     when 6   let month_name = "June"
  57.     when 7   let month_name = "July"
  58.     when 8   let month_name = "August"
  59.     when 9   let month_name = "September"
  60.     when 10  let month_name = "October"
  61.     when 11  let month_name = "November"
  62.     when 12  let month_name = "December"
  63.     otherwise
  64.       error "Invalid month number."
  65.       let month_name = "Invalid"
  66.   end case

  67.   return month_name
  68. end function  { Month_Integer_to_String }


  69. {***********************************************************************
  70.   Max_Day_of_Month
  71.   This function receives a month and year number as input, and
  72.   calculates the what the largest day of this month was.  (Yes, it
  73.   does account for leap years.)

  74.     Input:  month_num                small integer from 1 to 12
  75.             year_num                small integer

  76.     Output: max_day                smallint (28, 29, 30 or 31)
  77. ***********************************************************************}
  78. function Max_Day_of_Month (month_num, year_num)
  79.   define month_num, year_num, max_day                smallint

  80.   case (month_num)
  81.     when 1  { January   }
  82.       let max_day = 31
  83.     when 2  { February  }
  84.       if year_num mod 4 = 0 then
  85.         let max_day = 29
  86.       else
  87.         let max_day = 28
  88.       end if
  89.     when 3  { March     }
  90.       let max_day = 31
  91.     when 4  { April     }
  92.       let max_day = 30
  93.     when 5  { May       }
  94.       let max_day = 31
  95.     when 6  { June      }
  96.       let max_day = 30
  97.     when 7  { July      }
  98.       let max_day = 31
  99.     when 8  { August    }
  100.       let max_day = 31
  101.     when 9  { September }
  102.       let max_day = 30
  103.     when 10 { October   }
  104.       let max_day = 31
  105.     when 11 { November  }
  106.       let max_day = 30
  107.     when 12 { December  }
  108.       let max_day = 31
  109.   end case

  110.   return max_day
  111. end function  { Max_Day_of_Month }


  112. {***********************************************************************
  113.   End_of_Next_Month
  114.   This function receives a date as input, and returns a date which is
  115.   the last day of the next month.

  116.     Input:  input_date                date

  117.     Output: output_date                date
  118. ***********************************************************************}
  119. function End_of_Next_Month (input_date)
  120.   define input_date, output_date                date
  121.   define month_num, year_num, max_day                smallint

  122.   call Add_Month (month (input_date), year (input_date))
  123.                  returning month_num, year_num

  124.   call Max_Day_of_Month (month_num, year_num) returning max_day

  125.   let output_date = mdy (month_num, max_day, year_num)

  126.   return output_date
  127. end function  { End_of_Next_Month }


  128. {***********************************************************************
  129.   First_Day_of_Month
  130.   This function receives a date as input, and returns a date which is
  131.   the first day of the current month.

  132.     Input:  input_date                date

  133.     Output: output_date                date
  134. ***********************************************************************}
  135. function First_Day_of_Month (input_date)
  136.   define input_date, output_date                date

  137.   let output_date = mdy (month(input_date), 1, year(input_date))

  138.   return output_date
  139. end function  { First_Day_of_Month }


  140. {***********************************************************************
  141.   Last_Day_of_Month
  142.   This function receives a date as input, and returns a date which is
  143.   the last day of the input month.

  144.     Input:  input_date                date

  145.     Output: output_date                date
  146. ***********************************************************************}
  147. function Last_Day_of_Month (input_date)
  148.   define input_date, output_date                date
  149.   define max_day                                smallint

  150.   call Max_Day_of_Month (month (input_date), year (input_date))
  151.                returning max_day

  152.   let output_date = mdy (month (input_date), max_day, year (input_date))

  153.   return output_date
  154. end function  { Last_Day_of_Month }


  155. {***********************************************************************
  156.   Add_Month
  157.   This function accepts a month and year number as input, adds one
  158.   month and returns them.

  159.   Input:        month_num                smallint >=1 and <=12
  160.                 year_num                smallint
  161.   Output:        month_num                smallint >=1 and <=12
  162.                 year_num                smallint
  163. ***********************************************************************}
  164. function Add_Month (month_num, year_num)
  165.   define month_num, year_num                smallint
  166.   
  167.   if month_num < 12 then
  168.     let month_num = month_num + 1

  169.   else  { month_num = 12 }
  170.     let month_num = 1
  171.     let year_num  = year_num + 1
  172.   end if

  173.   return month_num, year_num
  174. end function  { Add_Month }


  175. {***********************************************************************
  176.   File_Date_Stamp
  177.   This function returns a date stamp of the current date suitable for
  178.   naming a file.

  179.     Input:  None

  180.     Output: p_date_char                char (8)
  181. ***********************************************************************}
  182. function File_Date_Stamp ()
  183.   define p_date                                        date
  184.   define p_date_char                                char (8)

  185.   let p_date = today
  186.   let p_date_char = p_date using "yyyymmdd"

  187.   return p_date_char
  188. end function  { File_Date_Stamp }


  189. {***********************************************************************
  190.   File_Time_Stamp
  191.   This function returns a time stamp of the current time (yymmddhhmm)
  192.   suitable for naming a file.

  193.     Input:  None

  194.     Output: time_stamp                        char (10)
  195. ***********************************************************************}
  196. function File_Time_Stamp ()
  197.   define p_date                                date
  198.   define p_date_char                        char (6)
  199.   define p_time                                datetime hour to minute
  200.   define p_time_char                        char (5)
  201.   define time_stamp                        char(10)

  202.   let p_date      = today
  203.   let p_date_char = p_date using "yymmdd"
  204.   let p_time      = current hour to minute
  205.   let p_time_char = p_time

  206.   let time_stamp = p_date_char, p_time_char [1,2], p_time_char [4,5]

  207.   return time_stamp
  208. end function  { File_Time_Stamp }
複製代碼


本帖子中包含更多資源

您需要 登錄 才可以下載或查看,沒有帳號?立即註冊

x
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 轉播轉播 分享分享 分享淘帖
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|Archiver|手機版|艾歐踢創新工坊    

GMT+8, 2024-6-13 03:54 , Processed in 0.275812 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表