To handle the last 2 days, the formula would be: now.startOf(day).subtract((2 - 1), day) To simplify, in our date picker we decided to use the following formula to calculate the start of the date range: now.startOf(relativeUnit).subtract(relativeAmount - 1, relativeUnit) Does that mean we should query data from last Friday at 3 pm to now? How about “last 2 days”? Is it 120 hours? For example, it is currently 3pm Friday and we would like data for the “last 7 days”. While these are common phrases we use, translating the phrase to a date range can be arbitrary. For example, a user may want data for the last day, last week or last month. Relative time range can be useful for users to select a common period of time. This improves consistency and avoids unnecessary conversions between multiple time zone.ĭisplaying date in UTC offset and abbreviations is perfectly fine, but internally using the IANA database format will make your life a lot easier. In our application, we store and pass any date state in UTC and only convert to the selected time zone when displaying. The databases get updated and thus reduce a lot of future headache for developers. Using IANA databases and libraries that accept them also means you would not need to update these timezone manually yourself when areas decide to change the timezone they observe. In our date picker we use moment-timezone to convert UTC time into the selected tz. IANA is the standard among numerous software systems such macOS, Android and GNU. To represent San Francisco we would use America/Los_Angeles in the database which contains both -7 and -8 offsets. The tz database is a collection of time zones by locations with daylight saving information included. To solve these problems we turned to IANA time zone database. For example, CST can mean any of the following: Central Standard Time, China Standard Time, Cuba Standard Time, making it even more confusing. On top of that, the same abbreviation can represent multiple zones. Selecting an abbreviation will cause the same daylight saving issue as UTC offset. For example, San Francisco can have either PST (Pacific Standard Time) or PDT (Pacific Daylight Time) time zones. There are also places that observe time in UTC+9:30 or UTC+12:45 for instances.Īnother common representation of timezone is an abbreviation. Also, note that the UTC offset isn’t always by hours. Say I want data between March 1 and April 30 in 2018 from a factory in San Francisco and I select UTC-7, the data would be represented incorrectly because from March 1 to March 11, the offset in San Francisco is UTC-8. Asking the user to select UTC offset can be problematic because of daylight saving. For example, right now in San Francisco the offset is UTC-7 hours. This format divides the world into different zones in which each one is plus or minus certain time off UTC. A common way is through Coordinated Universal Time (UTC) and offset. Handling time zone can be tricky especially because time zone rules are not consistent and time can be represented in many ways.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |