time zone in datetime

  • how do I attach a time zone to some string (the string should have no info of time zone)?

ActiveSupport::TimeZone.new(“Eastern Time (US & Canada)”).parse(“2011-11-14T00:00:00”)

result: Mon, 14 Nov 2011 00:00:00 EST -05:00

FILE_TIME_ZONE=ActiveSupport::TimeZone.new(“Pacific Time (US & Canada)”)

irb(main):014:0> FILE_TIME_ZONE.parse(“2011-02-14T01:00:00”)
=> Mon, 14 Feb 2011 01:00:00 PST -08:00
irb(main):015:0> FILE_TIME_ZONE.parse(“2011-05-14T01:00:00”)
=> Sat, 14 May 2011 01:00:00 PDT -07:00
Note about the Pacific Standard Time (PST) has one hour difference from Pacific daylight time PDT.

Note that if the string ends with “Z” it will treat as the string time as utc time

=> Sun, 13 Feb 2011 17:00:00 PST -08:00

  • How do I change a time with time zone to utc?


example: Time.now.utc

  • how do I convert a UTC DateTime to another time zone?
example: Time.now.in_time_zone("Central Time (US & Canada)")

distinct is based on all selected columns

select name, day from my_table;
| name       | day                |
| ABC       | 2011-11-13    |
| ABC       | 2011-11-13    |
| ABC       | 2011-11-14    |
| ABC       | 2011-11-14    |
| SURE    | 2011-11-15    |
| SURE    | 2011-11-15    |
| SURE    | 2011-11-16    |
| SURE    | 2011-11-16    |
10 rows in set (0.08 sec)

mysql> select distinct name, day from my_table;
| name             | day              |
| ABC   | 2011-11-13    |
| ABC   | 2011-11-14    |
| SURE | 2011-11-15    |
| SURE | 2011-11-16    |

Header Field cache-control

public (specify what can be cache-able)

Indicates that the response MAY be cached by any cache, even if it would normally be non-cacheable or cacheable only within a non- shared cache.

max-age (specify the expiration time)
Indicates that the client is willing to accept a response whose age is no greater than the specified time in seconds. Unless max- stale directive is also included, the client is not willing to accept a stale response.
must-revalidate (specify reload controls)
 the protocol also includes a mechanism for the origin server to require revalidation of a cache entry on any subsequent use. When the must-revalidate directive is present in a response received by a cache, that cache MUST NOT use the entry after it becomes stale to respond to a subsequent request without first revalidating it with the origin server. (I.e., the cache MUST do an end-to-end revalidation every time, if, based solely on the origin server’s Expires or max-age value, the cached response is stale.)

form_tag and form_for

they have different syntax, the former uses select_tag, field_text_tag, all ends with “_tag”

the latter, just f.select, f.field_text

form_for is for creating forms for one specific object/Model. It is less flexible, but saves you some typing as you don’t have to pass the model name in the element helpers over and over again.

form_tag (as all *_tag helpers) are not bound to that limitation. You could create a totally customized form that uopdates 2 1/2 different Models at the same time