TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How to handle date, time and timezones for an MVP

3 点作者 relaunched超过 8 年前
I&#x27;m building an mvp that has core functionality that involves setting date and times for future reminders. I have become completely overwhelmed by what I&#x27;ve read online. One can&#x27;t just use UTC time, nor can they just track timezones, because of daylight savings. There are tools like pytz, which is just one more tool I have to learn that&#x27;ll delay launching.<p>Given I can limit my scope for an MVP, what do you all think is a reasonable approach to handling date and time, for scheduling purposes, for an mvp.

3 条评论

niftich超过 8 年前
It seems you&#x27;re using python. The standard lib&#x27;s date and datetime classes are... not great.<p>A purpose-made library like Delorean [1] or Pendulum [2] will help with handling dates, datetimes, and timezones greatly, despite being another tool to learn. Even Arrow [3], which is popular because of its Moment.js-inspired API, is better than using the builtins, despite muddying a few concepts and making some design choices that I (or the Pendulum author [4]) don&#x27;t agree with.<p>In the Java world, Java 8&#x27;s builtin Datetime API and its predecessor Joda-Time are quite possibly the most thoroughly thought-out, expertly designed datetime libraries that exist today. In my opinion, none of the python libraries quite measure up, but Delorean and Pendulum are pretty solid.<p>[1] <a href="http:&#x2F;&#x2F;delorean.readthedocs.io&#x2F;en&#x2F;latest&#x2F;quickstart.html" rel="nofollow">http:&#x2F;&#x2F;delorean.readthedocs.io&#x2F;en&#x2F;latest&#x2F;quickstart.html</a> [2] <a href="https:&#x2F;&#x2F;pendulum.eustace.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pendulum.eustace.io&#x2F;</a> [3] <a href="http:&#x2F;&#x2F;crsmithdev.com&#x2F;arrow&#x2F;" rel="nofollow">http:&#x2F;&#x2F;crsmithdev.com&#x2F;arrow&#x2F;</a> [4] <a href="https:&#x2F;&#x2F;pendulum.eustace.io&#x2F;faq&#x2F;#why-not-arrow" rel="nofollow">https:&#x2F;&#x2F;pendulum.eustace.io&#x2F;faq&#x2F;#why-not-arrow</a>
brudgers超过 8 年前
Make an API call to Google? ][1] <a href="https:&#x2F;&#x2F;developers.google.com&#x2F;maps&#x2F;documentation&#x2F;timezone&#x2F;start" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;maps&#x2F;documentation&#x2F;timezone&#x2F;st...</a><p>An API call is going to be easier to implement than learning a new library.<p>[1]: Alternatives here: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;16086962&#x2F;how-to-get-a-time-zone-from-a-location-using-latitude-and-longitude-coordinates" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;16086962&#x2F;how-to-get-a-ti...</a>
评论 #12988539 未加载
welder超过 8 年前
Store in whatever format your scheduler uses, which is probably UTC or crontab format, no? For an MVP it doesn&#x27;t matter as long as it works.<p>After you outgrow your MVP the standard way to store datetimes for scheduling and rendering is:<p>1. <i>Always</i> store datetimes as UTC. You keep seeing this because it&#x27;s correct. Yes you can store in UTC and display or schedule in another timezone. Scheduling is easy when everything is in UTC.<p>2. Keep an Olson timezone string (America&#x2F;Los_Angeles) for each user server-side. Create a template filter for django&#x2F;flask to render your datetimes for the given user&#x27;s timezone. This is trivial for pytz and the built-in Python datetime library.<p>3. Use Moment.js and Moment-Timezone to render utc datetimes in the user&#x27;s current browser timezone. You can choose to use the server-side timezone or the browser&#x27;s timezone when rendering. I personally always use the server-side timezone.<p>Always do 1 and 2. 3 is optional if you prefer rendering datetimes server-side.<p>Edit: Why the downvotes? Anyone care to comment on why you think this way is wrong? It&#x27;s been working great for <a href="https:&#x2F;&#x2F;wakatime.com" rel="nofollow">https:&#x2F;&#x2F;wakatime.com</a>
评论 #12988092 未加载