脚本输出中更改日期的奇数问题 [英] Odd Issue of Date Changing in Script Output

查看:57
本文介绍了脚本输出中更改日期的奇数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一位同事编写了一个Google Apps脚本来自动化工作流程(批准酒店的房间兑换请求)。总的来说,剧本似乎按预期运作。脚本中有一个按照自动计划运行的功能(基于时间,而不是事件驱动)。有几种情况下入住日期已经过了一次,导致预订错误。不幸的是,它不会发生所有请求。所有提出请求的相关用户都在同一个时区(EST)。



例如,我看到了提交请求的入住日期为10/22和退房日期10/23,但是当剧本运行并且提交者收到通知时,入住日期将转移到10/21,并退房至10/22。



HTML电子邮件的相关部分只是简单地从电子表格行中提取值:
+

+Est Check In Date:+ Utilities.formatDate(row .drivalDate,EST,MM-dd-yyyy)
+

+Est签出日期:+ Utilities.formatDate(row.departureDate,EST,MM-dd -yyyy)



什么会导致这种行为?这可能是因为执行代码的给定Google服务器上的时间?

解决方案

我有类似的问题,但是我的输入日期格式为MM / dd / yyy。
当从电子表格中获取日期发布到电子邮件时,它总是少一天。



我在东部时间(GMT-5: 00)。我验证了它在我的项目属性和我的电子表格设置中是正确的。深入挖掘后,我意识到尽管表单中输入的日期和电子表格中显示的日期为2012年7月27日,但电子表格中的实际日期为:

Thu Jul 26 21:00:00 PDT 2012



这让一些感觉,因为7/27/2012 00:00:00东部时间(格林威治标准时间-5:00)将在PDT前一天三个小时。我只是格式化了日期GMT。我可以将它格式化为EDT,并且它应该始终有效,但是如果代码需要随季节变化而更改,那么对它进行硬编码或多或少会让别人读取代码时发生猜测。我只需要日期。



我在这篇文章中复制并粘贴了FUS1示例(现在作为注释),作为处理问题的更有说服力的方式。谢谢!


A colleague of mine has written a Google Apps script to automate a workflow (approving room comp requests at a hotel). The script, by and large, seems to be functioning as expected. There is a function in the script that runs on an automated schedule (time based, not event driven). There have been several instances where the check-in date has been off by one, leading to a booking error. Unfortunately, it does not occur for all requests. All relevant users making the requests are in the same timezone (EST).

For example, I've seen incidents where a request is submitted with a check-in date of 10/22 and a check-out date of 10/23 but when the script runs and the submitter receives notice of the approval the check-in date shifted to 10/21 and check-out to 10/22.

The relevant portion of the HTML email is simply pulling values from a spreadsheet row: + "

" + "Est Check In Date: " + Utilities.formatDate(row.arrivalDate, "EST", "MM-dd-yyyy") + "

" + "Est Check Out Date: " + Utilities.formatDate(row.departureDate, "EST", "MM-dd-yyyy")

What could cause this behavior? Could this be because of the time on a given Google server where the code is executed?

解决方案

I had a similar problem but mine was from entering the date in a form in the format MM/dd/yyy. When getting the date from the spreadsheet to post to an email, it was always one day less.

I'm in Eastern time (GMT-5:00). I verified that it was correct in my Project properties and my Spreadsheet setting. After digging deeper, I realized that although the date entered in the form and displayed in the spreadsheet was 7/27/2012 the actual date in the spreadsheet was:

Thu Jul 26 21:00:00 PDT 2012

This made "some" sense, as 7/27/2012 00:00:00 Eastern Time (GMT-5:00) would be the day before in PDT by three hours. I simply formatted the date GMT. I could have formatted it to EDT, and it should have always worked, but hard coding it GMT more or less took the guessing out of someone else reading the code if the code would need to be changed as the seasons changed. I only needed the date.

I did copy and paste the FUS1 example in this post (for now as comments) as a more "eloquent" way of handling the problem. Thanks!

这篇关于脚本输出中更改日期的奇数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆