计算工时小程序

每次月末看到到家都在计算工时够不够,好辛苦,还容易出错,于是就写了个小程序给大家用

大大的彩蛋https://mp.csdn.net/postedit/82686446

package util

import scala.collection.mutable.ArrayBuffer
import scala.io.Source

object WorkTimeHelper extends App {
  val excption = ArrayBuffer[String]()
  val workTimeList = Source.fromFile("c:/workTime.txt");
  var result: Int = 0
  workTimeList.getLines().foreach(e => result += convert(e))
  println("result = " + result)
  println("excption = " + excption)

  def convert(dayItem: String): Int = {
    val arr = dayItem.split("\t")
    if (arr(1) > "09:00" | arr(2) < "17:30") {
      excption += dayItem
      0
    }
    val begin = arr(1).split(":")
    val end = arr(2).split(":")
    val less = begin(1).toInt
    val more = if (end(0).equals("17")) 0 else (end(0).toInt - 18) * 60 + end(1).toInt
    more - less
  }
}
 
txt的文件数据格式如下,\t 分隔
2017-09-22	08:14	17:34	
2017-09-21	08:13	17:37
。。。。。。。。	

 

 

 

你可能感兴趣的:(scala)