Web developer ã®å¤§åº (@ohbarye) ã§ãã
ä»åã¯ã¿ã¤ã ã¾ã¼ã³ã«ã¾ã¤ããã話ããããã¨æãã¾ãã
ã¿ã¤ã ã¾ã¼ã³ã¯ç§ã Quipper ã«å ¥ç¤¾ããã°ããã®é ã«æãé ãæ©ã¾ãããã¨ã®ä¸ã¤ã§ããå ¥ç¤¾ä»¥åã«ã¯ã¿ã¤ã ã¾ã¼ã³ãè·¨ããããªã°ãã¼ãã«ãªã¢ããªã±ã¼ã·ã§ã³ã®éçºãå ¨ããã¦ããªãã£ãã®ã§ãã¾ãã«ã¼ãããå¦ã³ãèããããã¦ãããã¾ãããä»ã§ãæ°ãæãã¨ãããããã§ãã
å ¥ç¤¾ããããã1å¹´ããã®éã«å¾ãçµé¨ã¨ç¥èãæ´»ãããã¿ã¤ã ã¾ã¼ã³ã¨åãåããã¯ããã¯ãã¾ã¨ãã¦ã¿ããã¨æãã¾ãã
ç®æ¬¡
- ã¯ããã«
- åæ - Quipper ã®ãç´¹ä»
- é£ãã
- ç¾å¨æå»ãæ±ãåé¡
- è¨èªããã¬ã¼ã ã¯ã¼ã¯ã®å®è£
- èªç¥ã®åé¡
- ã¿ã¤ã ã¾ã¼ã³ãèæ ®ããè¨è¨ã®åé¡
- 解æ³
- åºæ¬çãªèãæ¹
- ããã©ã«ãã¿ã¤ã ã¾ã¼ã³ãè¨å®ãã
- ã¿ã¤ã ã¾ã¼ã³ãæèããè¨è¨
- ã¿ã¤ã ã¾ã¼ã³ãæèããããã°ã©ãã³ã°
- å ¥å
- æ°¸ç¶å
- åºå
- ã¿ã¤ã ã¾ã¼ã³ãæèãããã¹ã
- ã¦ããããã¹ã
- ã¤ã³ãã°ã¬ã¼ã·ã§ã³ãã¹ã
- ãã¹ãã®å¤±æ
- ã¹ã¿ã
- ã¿ã¤ã ã¾ã¼ã³ãæèãããã¼ã
- çµããã«
- åç¥
- åè
ã¯ããã«
ã¾ãã¯ããã«ãç§ã¯ãã¿ã¤ã ã¾ã¼ã³ãæ±ãã¤ã¤å ç¢ãªã³ã¼ããæ¸ãã®ã¯é£ãããã¨èãã¦ãã¾ãã
ä½ããã£ã¦é£ããã¨æãããã¯å¾è¿°ãã¾ãããé£ãããããã«ç§ã¯ã¿ã¤ã ã¾ã¼ã³çµ¡ã¿ã®åé¡ã«å¹¾ã¤ããããã¾ããããweb ä¸ã§ãåããããªåé¡ã«æ©ã人ãææè¦ããã¾ããåé¡ãé¿ãã or 解決ããããã«ã¯çµé¨ããããã¨ãªããããã¿ã¤ã ã¾ã¼ã³ã¯ãã«ãã¹ã¬ããããã°ã©ãã³ã°ã®ããã«ããèªä½ãé£ãããæ±ãã¦ãããã¨ããåæã«ç«ã¤å¿ è¦ãããã¨ç§ã¯èãã¦ãã¾ãã
ãã®è¨äºãç§ã¨åããããªæ©ã¿ã«ç´é¢ãã¦ããæ¹ããããããã®é£ããã«ç´é¢ããæ¹ã®ãå½¹ã«ç«ã¦ã°å¹¸ãã§ãã
ï¼ä½è«ã§ãããããæãã¿ã¤ã ã¾ã¼ã³ã¯è¾ããããè¾ãããããªã©ã¨éçºè éã§è©±ãã¦ããæãç§ä»¥ä¸ã«ã¿ã¤ã ã¾ã¼ã³ã¨é·ãåãåã£ã¦ãã CTO ãããããªå±ã¾ãã®è¨èããããã¾ããããããã§ãè¾ãããããã§ãã°ãã¼ãã«ãªãµã¼ãã¹ã®éçºè ã¨ãã¦åãåã£ã¦ãããï¼ãã¨ããæ°æã¡ãæ°ãã«ãã¾ããï¼
åæ - Quipper ã®ãç´¹ä»
æã Quipper ãã©ããã£ããµã¼ãã¹ãéçºãã¦ãããããèªèããã ããæ¹ãåãåã£ã¦ãã課é¡ã®ã¤ã¡ã¼ã¸ã湧ããããã¨æãã¾ãã®ã§ãç°¡åã«ãç´¹ä»ãã¾ãã
- Quipper 㯠Quipper School / Quipper Video ã¨ããå çã»çå¾åãã®ã°ãã¼ãã«ãªã¢ããªã±ã¼ã·ã§ã³ãéçºãã¦ãã¾ãã
- 2016å¹´ç¾å¨ãQuipper School ã¯ãã£ãªãã³ã»ã¤ã³ããã·ã¢ã»ã¡ãã·ã³ã»ã¿ã¤ã»ãããã ã»æ¥æ¬ã®6ã«å½ãQuipper Video ã¯ãã£ãªãã³ã»ã¤ã³ããã·ã¢ã»ã¡ãã·ã³ã®3ã«å½ã§å±éãã¦ãããããã«æ¡å¤§ãããã¨ãã¦ããã¨ããã§ãï¼
- ã¹ã¿ãã£ãµããªé«æ ¡è¬åº§ã»å¤§å¦åé¨è¬åº§ã¨ããå®å ¨ã«æ¥æ¬å½å åãã®ã¢ããªã±ã¼ã·ã§ã³ãæä¾ãã¦ãã¾ãã
ãããã®ã¢ããªã±ã¼ã·ã§ã³ã¯åãã³ã¼ããã¼ã¹ãªã®ã§ãæ¬è¨äºã§è¿°ã¹ã話ã¯ã©ã¡ãã®ã¢ããªã±ã¼ã·ã§ã³ã§ãèããªããã°ãããªããã®ã§ãã
ã¾ããæ¬ç¨¿ã¯ãããã® web çã§ãã Rails ã¢ããªã±ã¼ã·ã§ã³ã«ã¾ã¤ãã話ã§ããã³ã¼ãã RubyãRails ã®ä¾ãä¸å¿ã§ããåºæ¬çãªèãæ¹ã¯è¨èªã»ãã¬ã¼ã ã¯ã¼ã¯ãåãã¾ããã
é£ãã
ã¾ããæ¥æã»æå»ã¨ã¿ã¤ã ã¾ã¼ã³ã¯ä¸å¯åã§ããããã¿ã¤ã ã¾ã¼ã³ã¯é£ãããã¨è¨ãæã«ã¯ããããã®é£ãããæ··å¨ãã¦ãããã¨ãèªèãã¾ãããã
代表çãªåé¡ãè¦ã¦ããã¾ãã
ç¾å¨æå»ãæ±ãåé¡
ç¾å¨æå»ã¨ããã®ã¯ããã°ã©ããå¶å¾¡åºæ¥ãªãå¤é¨ããã®å ¥åã§ãããã®ãããããã°ã©ã ã®ãããããªã¨ããã§èªç±ã«å ¥åãåãå ¥ããã¨å¤é¨ç°å¢ã¸ã®ä¾å度ãä¸ãã£ã¦ãã¾ããèªç±ã«åãããããã¹ããããããã®ãé£ãããªãã¾ãã
ï¼ã¯ãã¯ããã社ã«ããããç¾å¨æå»ããå¤é¨å ¥åã¨ããè¨è¨ã¨ããã®å®è£ ã®ãã¨ãããï¼
ããã¯ã¿ã¤ã ã¾ã¼ã³ãæãã«ãã¦ãèªããåé¡ã§ãããã¿ã¤ã ã¾ã¼ã³ãæ±ããã¨ããã¨ãã®åé¡ã«ã»ã¼ééããªãç´é¢ãã¾ãã
è¨èªããã¬ã¼ã ã¯ã¼ã¯ã®å®è£
Rails ã¢ããªã±ã¼ã·ã§ã³ã§ã¯æ¥æãæ±ãã¯ã©ã¹ãè¤æ°ããã¾ãã
ãããã®ã¯ã©ã¹ã¨ããããã®ã¡ã½ãããé常ã«ãããããã§ããåãã¯ã©ã¹ã®ã¡ã½ããã§ãã©ã®ã¿ã¤ã ã¾ã¼ã³ã«ä¾åããããç°ãªã£ããããã¾ãã æ¬ç¨¿ã§ã¯ãããã®åºå¥ã«ã¯è§¦ãã¾ãããã以ä¸ã®åã«çããããªãããã§ããã° API ãªãã¡ã¬ã³ã¹çãä¸èªãã¦ã¿ã¾ãããã
Time
,Date
,DateTime
,TimeWithZone
ã®éãã¯ï¼Date.today
ã¨Date.current
ãTime.now
ã¨Time.zone.now
ããããã®éãã¯ï¼
ã¾ããæå»ãã¿ã¤ã ã¾ã¼ã³ã®æ±ãããã¬ã¼ã ã¯ã¼ã¯ã®å é¨ã«é è½ããããã¨ã§å¤é¨ç°å¢ã¸ã®ä¾åãæ示çã«è¦ããªããªããããã«åé¡ãé£ãããããã¨ãããã¾ãã
èªç¥ã®åé¡
人éã¯ããããåä¸ã®ã¿ã¤ã ã¾ã¼ã³ã«çãã¦ãã¾ããåãæéã«è¤æ°ã®å ´æã«åå¨ãããã¨ãã§ããªãã®ã§ãã¿ã¤ã ã¾ã¼ã³ãè¡ã£ããæ¥ããããæèã ãã§ãåå¤ç²ãã¾ãã
æµ·å¤ã®æ ç¹ã¨ããåããããªã©ãã¦è¤æ°ã®ã¿ã¤ã ã¾ã¼ã³ãæèãããã¨ã¯ããã©ãæéã®æµãã®ä¸ã§èªåã®åå¨ãåå¾ããããã¨ã¯ããã¾ãããç°ãªãã¿ã¤ã ã¾ã¼ã³ã«ç§»ã£ã¦ãã移åå ã®ã¿ã¤ã ã¾ã¼ã³ãèªåã®æ¨æºã«ãªãã ãã§ãã
ã¿ã¤ã ã¾ã¼ã³ãæ±ãæã«äººã¯ããããèªç¥ã«æã£ã¦ããã®ã§ã以ä¸ã®ãããªéæ¿ãªæè¦ãåºã¦æ¥ããã¨ãããã¾ãã
ããã
ã«ãããã¯ãã ã¿ã¤ã ã¾ã¼ã³ãèããããã« ãã®ä¸ã«çã¾ãã¦ããã®ã§ã¯ãªããã ã ã«ãããããããã¿ã¤ã ã¾ã¼ã³ããã¨
ãªã®ã§ãã
ã¿ã¤ã ã¾ã¼ã³ãèæ ®ããè¨è¨ã®åé¡
æ©è½ãå®è£ æ¹å¼ã®è¨è¨æã«ã¿ã¤ã ã¾ã¼ã³ã¸ã®é æ ®ã足ããªãã¨ãä¾ãã°ä»¥ä¸ã®ãããªåé¡ãèµ·ããã¾ãã
- ç¡æãã£ã³ãã¼ã³ã®é©ç¨æéã人ã«ãã£ã¦ç°ãªã£ã¦ãã¾ã
- 宿é¡ã®æåºæéã«é¢ãããã¼ã*1ãã§ãã¦ãã¾ã
- 決æ¸ã®å ¥éãè«æ±ã¨ãã£ãã¯ãªãã£ã«ã«ãªå¦çã®ã¿ã¤ãã³ã°ãããã¦ãã¾ã
ãããé¿ããããã«ã¯å®è£ æããã¡ããããã以åã®è¨è¨æ®µéãã以ä¸ã®ãããªãã¤ã³ãã«æ°ãã¤ããªããã°ããã¾ããã
- åæ©è½ã«ããã¦ã©ã®ã¿ã¤ã ã¾ã¼ã³ãä¿¡é ¼ããã¹ãã
- ç¹å®ã®ã¢ãã«ã«ã¿ã¤ã ã¾ã¼ã³ãæãããã¹ããã©ãã
- ã¯ã©ã¤ã¢ã³ãå´ã®ã¿ã¤ã ã¾ã¼ã³ãä¿¡é ¼ããã¹ããã©ãã
解æ³
ãããã㯠Quipper ã§å®è·µãã¦ãããã¨ãéçºæã«æèãã¦ãããã¨ãã¾ã¨ãã¦ããã¾ãã
åºæ¬çãªèãæ¹
ããã¯ããããæ¢ã«ãã¹ããã©ã¯ãã£ã¹ã¨ãã¦ç¥ããã¦ãããã¨ã¨æãã¾ãããã°ãã¼ãã«ãªã¢ããªã±ã¼ã·ã§ã³ã§ã¯ä»¥ä¸ã®3ç¹ãå¿ ãå®ãããã«ãã¾ãã
- ãã¼ã¿ãã¼ã¹ã¨ã¢ããªã±ã¼ã·ã§ã³ãã¬ã¼ã ã¯ã¼ã¯ã®ããã©ã«ãã¿ã¤ã ã¾ã¼ã³ãåå®ä¸çæ (UTC) ã«çµ±ä¸ãã
- æ¥æã®å ¥åæã«ã¯ã©ã®ã¿ã¤ã ã¾ã¼ã³ã«ä¾åããå¤ãªã®ããèæ ®ãã
- æ¥æã®åºåæã«ã¯é©åãªå½¢ã«æ´å½¢ãã (ã¨ã¹ã±ã¼ãã¯åºåæã«è¡ãã®ã¨åãã¤ã¡ã¼ã¸)
ã¡ãªã¿ã« Quipper ã§ã¯å®å ¨å½å åãã®ãµã¤ããä¾ãã°ã¹ã¿ãã£ãµããªã®æ±ºæ¸ãµã¤ãã«ã¤ãã¦ãã以ä¸ã®çç±ãããã®ã«ã¼ã«ãé©ç¨ãã¦ãã¾ãã
- åãµã¤ããä¾åããä»ã®ã¢ããªã±ã¼ã·ã§ã³ã®ããã©ã«ãã UTC ã§ãã
- è¤æ°ã®ã¢ããªã±ã¼ã·ã§ã³ã®éã§ããã©ã«ãã¿ã¤ã ã¾ã¼ã³ãç°ãªãã¨ãå®è£ ã»ã¬ãã¥ã¼æã«è³ã®ã¹ã¤ããã³ã°ã³ã¹ããå¢ãã
- æéã¸ã®çµ±ä¸çãªã³ã¼ããæ¸ããªãã®ã§äºæ ãå¤ãçºçãã
æ¢ã«ã°ãã¼ãã«ãªã¢ããªã±ã¼ã·ã§ã³éçºã«æé©åããããã¼ã ãªã®ã§ããã®æ¨æºããããããå¤ããæ¹ããªã¹ã¯ãé«ãã¨å¤æãã¾ããã
ããã©ã«ãã¿ã¤ã ã¾ã¼ã³ãè¨å®ãã
ä½ã¯ã¨ãããä¸è¿°ã®éãããã©ã«ãã¿ã¤ã ã¾ã¼ã³ã UTC ã«è¨å®ãã¾ãã
å®å ¨å½å åãã®ã¢ããªã§ããã° JST ã§ãæ§ããªãã§ãããç°ãªãã¿ã¤ã ã¾ã¼ã³ãèæ ®ããã¿ã¤ãã³ã°ãä¸åº¦ã§ãå ¥ã£ã¦ããã¨ç ´ç¶»ããå±éºãããã¾ãã
PostgreSQL
alter database my_database set timezone to 'UTC';
ã¾ãã¯
# postgresql.conf timezone = 'UTC'
Rails
# config/application.rb config.time_zone ='UTC' config.active_record.default_timezone = :utc
ã¿ã¤ã ã¾ã¼ã³ãæèããè¨è¨
ã³ã¼ããæ¸ãå§ããåã«ãããããã¯ã¿ã¤ã ã¾ã¼ã³ãæèããªããã°ãªããªããªãã¨æ°ä»ããã¼ã¯ã¼ããããã¾ããæéãæå»ãç· åãæéãéå§æ¥æãçµäºæ¥æãå®æ⦠ãããã¨ééããæã«ã¯æ°ãå¼ãç· ãã¾ãã
ã¿ã¤ã ã¾ã¼ã³ãæèããã°ãªããªãæãã©ã®åä½ã§æèããªããã°ãããªãã®ããèãã¾ãã
"ã¿ã¤ã ã©ã¤ã³ã«è¡¨ç¤ºãããæ¥æ"ã¯ã¯ã©ã¤ã¢ã³ããã·ã³ã®ã¿ã¤ã ã¾ã¼ã³ã«åããã¦æå»è¡¨ç¤ºã¯åãæ¿ãã£ã¦ãããã®ã§ããã"ãã£ã³ãã¼ã³æéã®çµäºæ¥æ"ã¯ã¦ã¼ã¶ã¼ã®ã¿ã¤ã ã¾ã¼ã³ã«é¢ãããå ¨ä¸çã§çµ±ä¸ãããã¿ã¤ãã³ã°ã§çµããã¹ãã§ãã
ã¾ããã¦ã¼ã¶ã¼ãæ¥æãå ¥åããéã«ã¯è¦æ³¨æã§ãããã©ã®ã¿ã¤ã ã¾ã¼ã³ã§æ±ãã¹ããããè¨ãæããã°ãã©ã®ã¿ã¤ã ã¾ã¼ã³ãåæã«ãã¦å ¥åãããå¤ãããå ¥å¿µã«æèããå¿ è¦ãããã¾ãã
ã¿ã¤ã ã¾ã¼ã³èªä½ã1ã¤ã®å ¥åé ç®ã¨ãã¦æããããã¨ãããå¾ã¾ãããããªãã®ã¿ã¤ã ã¾ã¼ã³ã¯ã©ãã§ããï¼ãã¯ã¦ã¼ã¶ã¼ãã¬ã³ããªã¼ã§ã¯ãªãã§ãããã©ãã®å½ï¼å°åã«ãä½ã¾ãã§ããï¼ããªãè¯ãã§ããããã¡ãªã¿ã« Quipper ã§ã¯ç¤¾å åãã®ãã£ã³ãã¼ã³å ¥ç¨¿æ©è½ãªã©ã§ã¯åå½ã®ã¹ã¿ããã«ã¿ã¤ã ã¾ã¼ã³ãå ¥åãã¦ããã£ã¦ãã¾ãã
ã¿ã¤ã ã¾ã¼ã³ãæèããããã°ã©ãã³ã°
ã¢ããªã±ã¼ã·ã§ã³å ¨ä½ãéãã¦ã·ã¹ãã ã¿ã¤ã ã¾ã¼ã³ã¸ã®ä¾åãåãå»ãã¾ãã ã¿ã¤ã ã¾ã¼ã³ã®åé¡ã«éããå¤é¨è¦å ãå®è¡ç°å¢ã«ä¾åããæç¹ã§ããã¯ä¸å®å®ãªå®è£ ã§ãã
å ¥å
ç¾å¨æå»ãåå¾ããéã«ã¯ã·ã¹ãã ã¿ã¤ã ã¾ã¼ã³ã«ä¾åããªãã¡ã½ããã使ãã¾ããTime.zone.now
ã使ãTime.now
ã¯ä½¿ããªããDate.current
ã使ã Date.today
ã¯ä½¿ããªããã¨ãã£ãå
·åã§ãã*2
ç¹å®ã®å¦çã ããç¹å®ã®ã¿ã¤ã ã¾ã¼ã³ã§è¡ãããå ´å Time.use_zone
ããããå¯è½ã«ãã¾ããã³ã¼ãã®æå³ãæ示çã«ãªãã®ã§å¿
è¦ãªç®æã§ã¯ç©æ¥µçã«æ´»ç¨ãã¾ãããã
Time.zone = 'UTC' Time.zone.now # => Thu, 04 Feb 2016 10:00:00 UTC +00:00 Time.use_zone('Asia/Tokyo') { Time.zone.now } # => Thu, 04 Feb 2016 19:00:00 JST +09:00
ã¬ãã¥ã¼ã®åº¦ã«ã¿ã¤ã ã¾ã¼ã³è¦å¯ã¨åãã®ãã¾ã大å¤ãªã®ã§ã以ä¸ã®ãããªã¢ã³ãã¼ããããå©ç¨ãããã¨ãããã¾ãã
class Date def self.today raise 'Use Date.current instead of Date.today' end def self.tomorrow raise 'Use Date.current + 1.day instead of Date.tomorrow' end end
æ°¸ç¶å
æå»ãæã¤ã«ã©ã 㯠Date åã§ã¯ãªã Time åã«ãããã¨ãæ¨å¥¨ãã¾ãã
Rails ã§ã¯ Date åã®ã«ã©ã ã« Time åã渡ã㨠Time ã¤ã³ã¹ã¿ã³ã¹ãæã£ã¦ããæå»ã§ã¯ãªã DB ã®ããã©ã«ãã¿ã¤ã ã¾ã¼ã³ã«å¤æãããå¤ã®æ¥æ¬¡é¨åã®ã¿ãä¿åããã¦æ¥æãããããã¨ãããã¾ãã
ãã®ä¾ã«ã¤ãã¦ã¯å¼ç¤¾é·æ°¸ (@kyanny) ã«ãããRails ã¨æå» - @kyanny's blogãããåç §ãã ããã
åºå
å è¿°ã®éããåºæ¬çã«ã¯ UTC ã§ä¿æãã¦ããã¨èªèããä¸ã§ãå¿ è¦ãªã¨ããã§å¿ è¦ãªå¤æãããã¦ããã¾ãã以ä¸ã®ãã㪠helper method ã view ã®ããã«ç¨æããã¨å¹ççã§ãã
def localize(time, zone) I18n.l time.in_time_zone(zone) end time = Time.zone.now localize(time, 'UTC') # => "Tue, 28 Nov 2016 15:14:05 +0000" localize(time, 'Asia/Tokyo') # => "Tue, 29 Nov 2016 00:14:05 +0900"
ã¾ããã¢ãã¤ã«ã¢ããªã Single Page Application ã§ã¯ã©ã¤ã¢ã³ãã«ä¾åããã¿ã¤ã ã¾ã¼ã³ã§æ¥æã表示ãããæ㯠API ã¨ã³ããã¤ã³ãããæ¥ä»ã®æåå表ç¾ãç´æ¥è¿ãããUNIX ã¿ã¤ã ã¹ã¿ã³ãã渡ãã¦ãã¾ãããã£ã¼ã«ãåãã¿ã¤ã ã¹ã¿ã³ãã ã¨ãããããã«ãã¦ããã¨åã¯ã©ã¤ã¢ã³ããµã¤ãã¨ã®ã³ãã¥ãã±ã¼ã·ã§ã³ãåæ»ã«ãªãã¾ãã
render json: { created_ts: user.created_at.to_i }
ã¿ã¤ã ã¾ã¼ã³ãæèãããã¹ã
ã¦ããããã¹ã
ç¾å¨æå»ã«é¢ããã¦ããããã¹ãã«ã¤ãã¦ã¯åç°å人ããã«ãããã¹ã容ææ§è¨è¨ã®è©±ã大å¤åèã«ãªãã¾ãã
åè¨äºã§ã¯å¹¾ã¤ãã®ã¢ããã¼ããç´¹ä»ããã¦ãã¾ããããã®ãã¡ãç¾å¨æå»ãå¼æ°ã§æ¸¡ããããæ¹ã«ã¤ãã¦ã¯ã¯ãã¯ããã社ã®ããç¾å¨æå»ããå¤é¨å ¥åã¨ããè¨è¨ã¨ããã®å®è£ ã®ãã¨ããæ¹ãã¦åèã«ãªãã¾ããå社㯠Trice ã®ãããªã©ã¤ãã©ãªã§ç¾å¨æå»ã®åå¾ã®å±æåãå®ç¾ãã¦ããã¨ã®ãã¨ã§ããããã§ã¦ããããã¹ããæ¯è¼ç容æã«æ¸ãã¦ããã®ã§ã¯ã¨æ¨å¯ãã¾ãã
ç§éã¯ãã®ã©ã¤ãã©ãªã使ç¨ãã¦ãã¾ãããããã®ãããªåãçµã¿ããã¹ãã®å®¹ææ§ãä¸ããåèã«ãªãã¾ãã
ã㦠Quipper ã®ãã¹ãã§ã¯ã©ããã¨ããã¨ããæå»ã©ã¤ãã©ãªã«ä»å
¥ãããã¢ããã¼ãã主ã«æ¡ç¨ãã¦ãã¾ããTime.now
èªä½ãã¹ã¿ããããããªãã¹ãããã«ã使ã£ãã¢ããã¼ãã§ãããã¹ãã®å¯¾è±¡ã¨ãªããããã¯ãã³ã¼ãã§ã¯ Time.zone.now
ãåæã§å¼ãã§ããããã®ã³ã¼ãã®ãã¹ãã§ã¯ Timecop
ãé½åº¦å©ç¨ãã¦ãã¾ãã
ãã®æ¹æ³ã®ã¡ãªããã¯ãããã¯ãã³ã¼ãå´ããã¹ããèæ ®ãã¦ããªãã¨ããã¹ããæ¸ãããã¨ããç¹ã§ããä¸ä¸ãã¹ãããªãã¡ã½ãããè¦ã¤ããã¨ãã¦ãããããã¯ãã³ã¼ãå´ã®å¤æ´ãªããã¹ãã追å ããäºãå¯è½ã§ãã
ãã®ã¢ããã¼ãã¯è¨èªã®æè»æ§ãé«ããã㤠Timecop
ã®ãããªä¿¡é ¼ãããã©ã¤ãã©ãªããã Ruby ã ããããåºæ¥ããã®ãªã®ã§ããã Quipper ã Java ã PHP ãªã©ä»ã®è¨èªãæ¡ç¨ãã¦ããã°ä»ã®ã¢ããã¼ããé¸æããå¯è½æ§ãé«ãã¨æãã¾ãããããã®æ¹æ³ãé·çãããã®ã§ãã®æã
ã«å¿ããã¢ããã¼ããåãã¹ãã¨èãã¾ãã
ã¤ã³ãã°ã¬ã¼ã·ã§ã³ãã¹ã
æ°¸ç¶åã¾ã§å«ããã¤ã³ãã°ã¬ã¼ã·ã§ã³ãã¹ãã§ã¯ãä¿åãããæ¥æãã¿ã¤ã ã¾ã¼ã³è¾¼ã§æ£ãããã©ããã¾ã§æ¤è¨¼ãã¾ãã
ãã¹ãã®å¤±æ
æ¥æé¢é£ã®ãã¹ããä¸å®å®ãªæã¯ãã¹ãã³ã¼ããã¾ã¼ã³ãèæ ®ãã¦ããªããããã¹ããããã³ã¼ããã¾ã¼ã³ãèæ ®ãã¦ããªãæã§ãã ããããã±ã¼ã¹ã¯å¥æ ç¹ã®éçºè ãæ°ä»ããã¨ãå¤ã*3ã®ã§ã GitHub issues ã Slack ã§ä¼ãã¦ç´ãã¦ããã£ãããã¾ãã
ã¾ããéçºè
ã¨é ãã¿ã¤ã ã¾ã¼ã³ (Time.zone = 'EST' (UTC-5)
) ããã㦠spec_helper.rb
ã§ã»ãããã工夫ããã¦ãã¾ã*4ãããã«ããã¾ã¼ã³ãèæ
®ãã¦ããªãã³ã¼ãããã¹ãã失æããæ¯è¼çæ©ã段éã§ééãã«æ°ä»ããã¨ãã§ãã¾ãã
ã¹ã¿ã
ãã¹ãã§æ¥æãã¹ã¿ãããé㯠Timecop ã®ãããªã©ã¤ãã©ãªãå©ç¨ãã¾ããRails 4.1 以ä¸ã§ããã°ãActiveSupport ã«ãã«ãã¼ã追å ããã¦ããã®ã§ãããã使ãã®ãè¯ãã§ãããã
ä½è«ã§ãããTimecop èªä½ãå¯ä½ç¨ããããããªãããã« safe_mode ã§ä½¿ç¨ãã¦ãã¾ãã
# spec/support/timecop.rb Timecop.safe_mode = true # spec/your/spec.rb around do |example| Timecop.freeze(target_time) { example.run } end
ã¿ã¤ã ã¾ã¼ã³ãæèãããã¼ã
ã¿ã¤ã ã¾ã¼ã³ã«éã£ã話ã§ã¯ãªãã§ããã誰ããä¸åº¦ããã£ãåé¡ã»ç¥èã»ãã¯ããã¯ãéçºè éã§å ±æãããã¨ã¯ã¨ã¦ã大äºã§ãã 以ä¸ã®è¨äºã¯ãã®ä¸ç°ã¨ãã¦ãã£ãªãã³ã® Joy ã¨ããéçºè ãæ¸ãã¦ãããè¨äºã§ãã
How to Tame Time Zones in Ruby on Rails
ããããç©ã¿éããã¿ã¤ã ã¾ã¼ã³ã«é¢ãããããã³ã³ã»ã³ãµã¹ãåãããã¼ã ãä½ã£ã¦ãããæ°ãã join ããéçºè ãåãåé¡ã«ã¤ãã¦ããã£ã¦ãå¿ ã誰ãããã©ãã¼ã§ããããã«ãªã£ã¦ãã¾ãã
çµããã«
ã¿ã¤ã ã¾ã¼ã³åé¡ã«ã¤ãã¦èªãæãã¢ã¸ã¢åã®éçºè ã¯å²ãé£ãåã¿ã¤ã ã¾ã¼ã³ã¨æåã³ã¼ãã«å¼·ãããããªã©ã¨åè«ããã¦è©±ããããã¾ããããã誰ããåãããããããããã§ã¯ãªããå¿ è¦ã«å¿ãã¦ãã£ããã¢ãããã¦ãããªã£ã¦ãããã®ã ã¨æãã¾ãã
ããããå¿ è¦æ§ã«ç´é¢ã§ããã®ã¯ãã¼ã±ãããåºãæã¡ããã¤è¤æ°ã®å½ã®éçºè ãååãã Quipper ãªãã§ã¯ã®ééå³ã§ãããã°ãã¼ãã«ãªãµã¼ãã¹ã«é¢å¿ã®ããéçºè ã«ã¨ã£ã¦ã¯åºæ¿çãªç°å¢ã ã¨å¼·ãæã£ã¦ãã¾ãã
åç¥
æå¾ã«åç¥ã§ããã Quipper ã¨ãªã¯ã«ã¼ããã¼ã±ãã£ã³ã°ãã¼ããã¼ãº (RMP) ååã® MeetUp ã¤ãã³ã第åå¼¾ãéå¬ãã¾ãï¼
- æé: 2016å¹´12æ13æ¥(ç«) 20:00 JST
- å ´æ: Quipper, RMP ãªãã£ã¹ (æ±äº¬é½ä¸å¤®åºäº¬æ©1-6-1ãä¸äºä½åæµ·ä¸ããã³ãã«8F)
- ç³è¾¼: https://rmp-quipper.connpass.com/event/46234/ ãããå¿åãã ããï¼
ç§ã¨ RMP ã®éè°· (@soplana) ãç»å£ãã"ã¨ã³ã¸ãã¢ã®çåæ¦ç¥"ããã¼ãã«ãã¨ã³ã¸ãã¢ã®ãã£ãªã¢ãã¹ãçµç¹ã¨ãã¦éå®ãããã¹ãã«ã«ã¤ãã¦å¯¾è«ãã¾ãã
QuipperãRMP å社ãã°ãã¼ãã«ãªãµã¼ãã¹ã®éçºã«èå³ãããæ¹ã¯æ¯éãåå ããã ããã¨å¬ããã§ãï¼
åè
æ¬è¨äºãæ¸ãã«ãããåèã«ããã¦ããã ããè¨äºã以ä¸ã«è¨ãã¾ãã
- How to Tame Time Zones in Ruby on Rails
- ãç¾å¨æå»ããå¤é¨å ¥åã¨ããè¨è¨ã¨ããã®å®è£ ã®ã㨠- ã¯ãã¯ãããéçºè ããã°
- ããã§ããªãããã¹ãé§åéçºãã¹ã¿ã¼ï¼ï¼åç°å人ããããã¹ãé§åéçºåé¡ã解çã³ã¼ã使ããªãã解説ãã¾ãï½ç¾å¨æå»ãé¢ãããã¹ãããããã¹ã容ææ§è¨è¨ãå¦ã¶ #tddï½CodeIQ MAGAZINE
- ã³ã¼ãå ã§ãç¾æå»ããæ°è»½ã«åå¾ãã¦ã¯ãããªã | Nekoya Press
- Rails ã¨æå» - @kyanny's blog
- Time zone in Rails
- Rubyã¨Railsã«ãããTime, Date, DateTime, TimeWithZoneã®éã - Qiita
- Railsã¨å¨è¾ºã®TimeZoneè¨å®ãæ´çãã (active_record.default_timezoneã®ç½ ) - Qiita
â Quipperæ¥æ¬ãªãã£ã¹ã§ã¯ä»²éãåéãã¦ãã¾ããæ¯éãæ°è»½ã«ãå¿åãã ãããâ
*1:"å¶ä½è ã®æå³ããªãåä½ããããä¸æ£è¡çº"ãæãã¾ãã
*2:ãããã®ã¯ã©ã¹ã¨ã¡ã½ããã®éãã«ã¤ãã¦ã¯ API ãªãã¡ã¬ã³ã¹ãRubyã¨Railsã«ãããTime, Date, DateTime, TimeWithZoneã®éã - Qiitaãªã©ã®è¨äºããå¦ã³ã¾ããã
*3:ãã³ãã³ã®æ¥ä¸ã« review / merge ãããæ©è½ãç¿æã®æ¥æ¬ã§ fail ããã¨ãã
*4:ãã®å·¥å¤«ã¯ããã³ãã³ã®éçºè 㯠UTC ãªã®ã§ãã¼ã«ã«ã§ã CircleCI ã§ããã¹ããéã£ã¦ãã¾ãããåãã³ã¼ããéãã³ãã³ã®éçºè ããã¼ã«ã«ã§æµãã¨è½ã¡ã (CircleCI ã§ã¯éã) ãã¨ããåé¡ãçºç«¯ã§ããã