<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="242978" data-post-id="242978">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="chavenor" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/chavenor/120/7459_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  chavenor
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/dimitarvp" rel="nofollow">@dimitarvp</a> so we should override and go with…</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">@timestamps_opts [type: :utc_datetime_usec]

</code></pre>
<p>I have an application that spans timezones, how do run reports and handle timezones between locations?   Pull the UTC out and then add the timezone data back to it?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="242978" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-use-utc-datetime-over-naive-datetime-for-ecto/32532/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-242978" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="242978"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="242979" data-post-id="242979">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="itssasanka" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  itssasanka
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes you can basically store the UTC timestamps and store timezones separately [preferably in tzdata ; ex: America/New_York]</p>
<p>You can use the Calendar module to apply shift operations.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="242979" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-use-utc-datetime-over-naive-datetime-for-ecto/32532/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-242979" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="242979"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="242981" data-post-id="242981">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You can use <a href="https://hexdocs.pm/tz_datetime/TzDatetime.html" class="inline-onebox" rel="nofollow">TzDatetime — tz_datetime v1.0.1</a> as a base for that.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="242981" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-use-utc-datetime-over-naive-datetime-for-ecto/32532/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-242981" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="242981"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="243056" data-post-id="243056">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="chavenor" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/chavenor/120/7459_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  chavenor
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="itssasanka" data-post="13" data-topic="32532">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/i/f05b48/48.png" class="avatar"> itssasanka:</div>
<blockquote>
<p>Calendar</p>
</blockquote>
</aside>
<p>Is the Calendar module not needed, at first glance at the documents for tz_datetime it looks like it transforms it when it saves and has a function to retrieve it.   As I move between locations and different timezones how would I set the timezone on save dynamically?  I didn’t really see how you would set the “American/New_York” in the documents or examples.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="243056" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-use-utc-datetime-over-naive-datetime-for-ecto/32532/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-243056" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="243056"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="243062" data-post-id="243062">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>How you figure out the timezone for things stored or which timezone to present data in is out of scope for the library. It only deals with the fact that timezone offsets might change while things are in the database, while making sure the db stores datetimes in utc for comparison/sorting purposes.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="243062" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-use-utc-datetime-over-naive-datetime-for-ecto/32532/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-243062" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="243062"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="243091" data-post-id="243091">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="itssasanka" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  itssasanka
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The <code>Calendar</code> module is not needed, but it is my go-to for all time-related operations as the library itself is very comprehensive and has some powerful APIs.<br>
<a href="https://github.com/lau/calendar" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/lau/calendar</a><br>
You would have your client to notify your server in some way about it’s new timezone. In terms of web apps, it should be straightforward to do it through JavaScript, for example.<br>
You can save that value (which is of the format <code>America/New_York</code>) as a String in your documents/tables.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="243091" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-use-utc-datetime-over-naive-datetime-for-ecto/32532/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-243091" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="243091"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="255735" data-post-id="255735">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kevinlang" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kevinlang
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>It is unfortunate that this cannot be done in Ecto because of backwards compatibility concerns, but it would be nice to do this by default for all new Phoenix applications.</p>
<p>I started a discussion about that on the mailing list if anyone is interested in following along:</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://groups.google.com/g/phoenix-core/c/dQA8zyCv93g">
  <header class="source">
      <img src="https://www.gstatic.com/images/branding/product/1x/groups_32dp.png" class="site-icon" alt="" width="32" height="32">

      <a href="https://groups.google.com/g/phoenix-core/c/dQA8zyCv93g" target="_blank" rel="noopener nofollow ugc">groups.google.com</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://groups.google.com/g/phoenix-core/c/dQA8zyCv93g" target="_blank" rel="noopener nofollow ugc">phoenix-core - Google Groups</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="255735" data-batch-url="/posts/batch_likers">
                        8
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-use-utc-datetime-over-naive-datetime-for-ecto/32532/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-255735" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="255735"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="283423" data-post-id="283423">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="fchabouis" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  fchabouis
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Everybody agrees about what should be done on Ecto’s side (use <code>:utc_datetime_*</code>).</p>
<p>But <a class="mention" href="/u/lostkobrakai" rel="nofollow">@LostKobrakai</a> advice is to use <code>timestamp</code> in the DB, while the links given by <a class="mention" href="/u/wojtekmach" rel="nofollow">@wojtekmach</a> seem to say otherwise (<a href="https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_timestamp_.28without_time_zone.29" class="inline-onebox" rel="noopener nofollow ugc">Don't Do This - PostgreSQL wiki</a> and <a href="https://www.amberbit.com/blog/2017/8/3/time-zones-in-postgresql-elixir-and-phoenix/" class="inline-onebox" rel="noopener nofollow ugc">Time zones in PostgreSQL, Elixir and Phoenix | AmberBit Sp. z o. o.</a>).</p>
<p>Is there a consensus?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="283423" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-use-utc-datetime-over-naive-datetime-for-ecto/32532/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-283423" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="283423"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="283429" data-post-id="283429">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="fchabouis" data-post="19" data-topic="32532">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/f/6a8cbe/48.png" class="avatar"> fchabouis:</div>
<blockquote>
<p>Is there a consensus?</p>
</blockquote>
</aside>
<p>I don’t think there can be unconditional consensus. As far as <code>ecto</code> is concerned <code>timestamp</code> and <code>timestamptz</code> work just the same. Ecto automatically ensures everything is in UTC. Postgres in theory shouldn’t convert anything for <code>timestamptz</code>, as datetimes are always utc.</p>
<p>Where the difference of those two come in is really how postgres behaves around other clients to the database.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="283429" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-use-utc-datetime-over-naive-datetime-for-ecto/32532/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-283429" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="283429"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>