# Time crate without dependencies

**URL:** <https://users.rust-lang.org/t/time-crate-without-dependencies/91082>\
**Category:** help\
**Created:** [March 18, 2023, 12:11pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082 "2023-03-18T12:11:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wenil](https://avatars.discourse-cdn.com/v4/letter/w/f08c70/32.png) [@Wenil](https://users.rust-lang.org/u/Wenil)\
**Post date:** [March 18, 2023, 12:11pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/1 "2023-03-18T12:11:13Z")

</div>

I am looking for a minimal time crate with no dependencies.

- no system time detection
- no parsing and formating  
I just want to be able to get the Duration between two DateTimes

Is there a crate that can do this?

---

<div class="post-metadata">

**Author:** ![jbe](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jbe](https://users.rust-lang.org/u/jbe)\
**Post date:** [March 18, 2023, 12:17pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/2 "2023-03-18T12:17:54Z")

</div>

What are "DateTimes" in that matter? Do you require time-zone support too?

---

<div class="post-metadata">

**Author:** ![2e71828](https://avatars.discourse-cdn.com/v4/letter/2/3e96dc/32.png) [@2e71828](https://users.rust-lang.org/u/2e71828)\
**Post date:** [March 18, 2023, 12:18pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/3 "2023-03-18T12:18:41Z")

</div>

What information do you have to construct a `DateTime` with, if not by parsing?

---

<div class="post-metadata">

**Author:** ![jbe](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jbe](https://users.rust-lang.org/u/jbe)\
**Post date:** [March 18, 2023, 12:26pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/4 "2023-03-18T12:26:17Z")

</div>

I think you can have year, month, day, hour, minute, second in UTC or any other time-zone that doesn't include [DST](https://en.wikipedia.org/wiki/Daylight_saving_time) switching, for example. Maybe that is what the OP is seeking. Hence my question on the time-zones.

---

<div class="post-metadata">

**Author:** ![Wenil](https://avatars.discourse-cdn.com/v4/letter/w/f08c70/32.png) [@Wenil](https://users.rust-lang.org/u/Wenil)\
**Post date:** [March 18, 2023, 12:52pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/5 "2023-03-18T12:52:14Z")

</div>

a type with year,month,day,hour,minute,second

with time-zone support

---

<div class="post-metadata">

**Author:** ![jbe](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jbe](https://users.rust-lang.org/u/jbe)\
**Post date:** [March 18, 2023, 1:08pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/6 "2023-03-18T13:08:13Z")

</div>

I think time-zone support always requires to draw in dependencies. That's because time zone data changes, and daylight-saving-time has an impact on the duration (in SI-[seconds](https://en.wikipedia.org/wiki/Second)) between two "DateTimes". For example, from 8 a.m. to 8 a.m. on the next day, it could be 24 hours, 23 hours, or 25 hours _(edit: disregarding [leap seconds](https://en.wikipedia.org/wiki/Leap_second), if you truly account for "SI-seconds")_.

---

<div class="post-metadata">

**Author:** ![stonerfish](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@stonerfish](https://users.rust-lang.org/u/stonerfish)\
**Post date:** [March 18, 2023, 1:31pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/7 "2023-03-18T13:31:14Z")

</div>

> [@Wenil](#):
>
> no system time detection

Is it even possible to find out a "time" without accessing the system clock?

---

<div class="post-metadata">

**Author:** ![jbe](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jbe](https://users.rust-lang.org/u/jbe)\
**Post date:** [March 18, 2023, 1:32pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/8 "2023-03-18T13:32:23Z")

</div>

Asking a server, asking the user, reading it from a database, etc.

---

<div class="post-metadata">

**Author:** ![jhpratt](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jhpratt/32/37974_2.png) [@jhpratt](https://users.rust-lang.org/u/jhpratt)\
**Post date:** [March 18, 2023, 5:35pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/9 "2023-03-18T17:35:06Z")

</div>

`time` has no dependencies when using no-default-features. Okay, _technically_ it has `time-core` as a dependency, but that's also controlled by me and is merely an implementation detail.

It supports fixed UTC offsets, but not "proper" tzdb time zones at the moment.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [June 16, 2023, 5:36pm UTC](https://users.rust-lang.org/t/time-crate-without-dependencies/91082/10 "2023-06-16T17:36:05Z")

</div>

Closed on June 16, 2023, 5:36pm UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
