- UID
- 10039329
- 热情
- 20264
- 人气
- 22094
- 主题
- 304
- 帖子
- 17354
- 精华
- 1
- 积分
- 30159
- 分享
- 0
- 记录
- 0
- 相册
- 0
- 好友
- 4
- 日志
- 0
- 在线时间
- 14880 小时
- 注册时间
- 2016-10-21
- 阅读权限
- 30
- 最后登录
- 2023-5-18
    
升级   50.8% - UID
- 10039329
- 热情
- 20264
- 人气
- 22094
- 主题
- 304
- 帖子
- 17354
- 精华
- 1
- 积分
- 30159
- 阅读权限
- 30
- 注册时间
- 2016-10-21
|
I don't know about grovvy. I think groovy is very interesting.
For your code, if I wrote in javascript or other languange, I will put following code in a function. By seperating the code into function, it is easy to read and of course you can unit test the function :-)
def queryString = [location: "${fields[1]},${fields[2]}", timestamp: 0, key: apiKey]
def response = forecastApi.get(query: queryString)
String zoneID = response.data.timeZoneId
DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = utcFormat.parse(fields[0]);
DateFormat pstFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
pstFormat.setTimeZone(TimeZone.getTimeZone(zoneID));
println "${fields[0]},${fields[1]},${fields[2]},${zoneID},${pstFormat.format(date)}"; |
|