GithubHelp home page GithubHelp logo

datetime's Introduction

rust-datetime datetime on crates.io Build status

Date/time library for Rust! Very much a work in progress.

Installation

This crate works with Cargo. Add the following to your Cargo.toml dependencies section:

[dependencies]
datetime = "0.5"

The earliest version of Rust that this crate is tested against is Rust v1.31.0.

datetime's People

Contributors

badboy avatar goyox86 avatar harrisonmetz avatar hoodie avatar ignatenkobrain avatar matrohin avatar mneumann avatar ogham avatar sylvestre avatar tl8roy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

datetime's Issues

Time zone awareness

There should be an easy way to get a LocalDateTime in one's local time zone, given a number of seconds since the epoch in UTC.

For instance, exa currently formats file modification times in UTC, in contrast to GNU ls which uses my time zone of UTC-9.

Wrong LocalDateTime

Using this crate gives a difference of two hours between the true time (also given by chrono) and real local time.

fn main() {
    println!("datetime: {:?}", datetime::LocalDateTime::now());
    println!("chrono: {}", chrono::Local::now());
}

datetime: LocalDateTime(2019-10-05T09:06:49.-17459)
chrono: 2019-10-05 11:06:49.310240511 +02:00

Switch from iso8601 to chrono

It looks like the iso8601 crate is no longer actively maintained: badboy/iso8601#19

It would be good to switch to the chrono crate. This will help reduce the amount of unmaintained code floating around.

The major difference is that iso8601 has more flexible parsing (it tries to autodetect the format), whereas chrono wants you to specify the format up-front.

Arguably iso8601's "magic behaviour" of parsing is potentially surprising and not such a great thing anyways, but if really needed one could maybe implement it using chrono's primitives.

shouldn't year() return a Year?

Hey, just for discussion:
I found datetime has a stuct Year etc.
Do you think it would make sense if the DatePiece methods returned the respective structs?

[2 in 1] datetime/exa issues

I've managed to compile exa on ARM using rust 1.5 and --no-default-features but first had to fix this by casting to i64:

Compiling datetime v0.4.2
/tmp/.cargo/registry/src/github.com-48ad6e4054423464/datetime-0.4.2/src/system.rs:38:6: 38:15 error: mismatched types:
 expected `i64`,
    found `i32`
(expected i64,
    found i32) [E0308]
/tmp/.cargo/registry/src/github.com-48ad6e4054423464/datetime-0.4.2/src/system.rs:38     (tv.tv_sec, (tv.tv_nsec / 1000) as i16)
                                                                                          ^~~~~~~~~
/tmp/.cargo/registry/src/github.com-48ad6e4054423464/datetime-0.4.2/src/system.rs:38:6: 38:15 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
Could not compile `datetime`.

only to find -l option doesn't work:

$  ~/exa-20160211 -l
thread '<main>' panicked at 'Unable to determine time zone', src/libcore/option.rs:334
stack backtrace:
   1: 0xb6ddf9df - sys::backtrace::tracing::imp::write::h86e39446169e67d0Wnt
   2: 0xb6de2513 - panicking::log_panic::_<closure>::closure.39676
   3: 0xb6de1f47 - panicking::log_panic::h7e0ce1e7485944fbUpx
   4: 0xb6dd1b87 - sys_common::unwind::begin_unwind_inner::h1d39a3f983dfda740gs
   5: 0xb6dd2507 - sys_common::unwind::begin_unwind_fmt::h2f77b9962e7023ac6fs
   6: 0xb6ddf053 - rust_begin_unwind
   7: 0xb6def38f - panicking::panic_fmt::h48301c5acd531c5bZEK
   8: 0xb6d1580b - option::_<impl>::expect::expect::h2570453751442068436
                at src/libcore/macros.rs:28
   9: 0xb6d150bf - output::details::_<impl>::default::h8a8ad7389276de4aFic
                at src/output/details.rs:171
  10: 0xb6d19297 - output::details::_<impl>::view::h4851bbe4ecd53aaakjc
                at src/output/details.rs:191
  11: 0xb6d58303 - _<impl>::print_files::h4dce2bbed8c81fe4ZRe
                at src/main.rs:137
  12: 0xb6d592ab - _<impl>::print_dirs::hd6db41078e88377a1Me
                at src/main.rs:129
  13: 0xb6d572db - _<impl>::run::h8dfb0d815e94decaZJe
                at src/main.rs:77
  14: 0xb6d5a23b - main::ha86e656adc12d327HSe
                at src/main.rs:151

Is it related or maybe 1.5 is already too old?

Month enum does not coerce into i32 nicely

Hello,

do you think it would cause breakage if Month was represented in this way:

pub enum Month {
    January   = 1,
    February  = 2,
    March     = 3,
    April     = 4,
    May       = 5,
    June      = 6,
    July      = 7,
    August    = 8,
    September = 9,
    October   = 10
    November  = 11,
    December  = 12,
}

This would allow it to be coerced into a an i32 more nicely without manually having to add 1 to get the actual number of the month. Your doc comment mentions the implementation as enum instead of as a number, but does not explicitly state why this wouldn't work to.

Thank you

PS: of course this would break everybody's code who have already manually added 1 to the month, but I would consider this acceptable for a 0.3.x release.

include LICENSE text

MIT requires license to be present along with source. Please include it (and if not hard, make new release). Thanks!

datetime 0.4.5 fails to build on i386

While updating exa to 0.8.0 on FreeBSD I stumbled across a build failure of datetime on FreeBSD 10.3/i386

error[E0308]: mismatched types                                                                                       
  --> cargo-crates/datetime-0.4.5/src/system.rs:76:6                                                                 
   |                                                                                                                 
76 |     (tv.tv_sec, (tv.tv_nsec / 1000) as i16)                                                                     
   |      ^^^^^^^^^ expected i64, found i32                                                                          

I'm currently patching it like this:

--- cargo-crates/datetime-0.4.5/src/system.rs.orig	2017-10-01 10:07:40 UTC
+++ cargo-crates/datetime-0.4.5/src/system.rs
@@ -73,7 +73,7 @@ fn file_time_as_u64(ft: &FILETIME) -> u64 {
 pub unsafe fn sys_time() -> (i64, i16) {
     let mut tv = libc::timespec { tv_sec: 0, tv_nsec: 0 };
     let _ = clock_gettime(libc::CLOCK_REALTIME, &mut tv);
-    (tv.tv_sec, (tv.tv_nsec / 1000) as i16)
+    (tv.tv_sec as i64, (tv.tv_nsec / 1000) as i16)
 }
 
 /// Returns the system’s current time, as a tuple of seconds elapsed since

Does not compile on nightly

   Compiling datetime v0.1.5
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:88:117: 88:127 error: type `collections::string::String` does not implement any method in scope named `as_slice`
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:88             Field::MonthName(true, a)     => a.format(w, locale.long_month_name(when.month().months_from_january()).as_slice()),
                                                                                                                                                                                                                                            ^~~~~~~~~~
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:88:117: 88:127 help: methods from traits can only be called if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:88:117: 88:127 help: candidate #1: use `core::str::Str`
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:89:118: 89:128 error: type `collections::string::String` does not implement any method in scope named `as_slice`
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:89             Field::MonthName(false, a)    => a.format(w, locale.short_month_name(when.month().months_from_january()).as_slice()),
                                                                                                                                                                                                                                             ^~~~~~~~~~
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:89:118: 89:128 help: methods from traits can only be called if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:89:118: 89:128 help: candidate #1: use `core::str::Str`
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:91:114: 91:124 error: type `collections::string::String` does not implement any method in scope named `as_slice`
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:91             Field::WeekdayName(true, a)   => a.format(w, locale.long_day_name(when.weekday().days_from_sunday()).as_slice()),
                                                                                                                                                                                                                                         ^~~~~~~~~~
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:91:114: 91:124 help: methods from traits can only be called if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:91:114: 91:124 help: candidate #1: use `core::str::Str`
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:92:115: 92:125 error: type `collections::string::String` does not implement any method in scope named `as_slice`
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:92             Field::WeekdayName(false, a)  => a.format(w, locale.short_day_name(when.weekday().days_from_sunday()).as_slice()),
                                                                                                                                                                                                                                          ^~~~~~~~~~
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:92:115: 92:125 help: methods from traits can only be called if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
/home/nate/.multirust/toolchains/nightly/cargo/registry/src/github.com-1ecc6299db9ec823/datetime-0.1.5/src/format.rs:92:115: 92:125 help: candidate #1: use `core::str::Str`
error: aborting due to 4 previous errors
Build failed, waiting for other jobs to finish...
Could not compile `datetime`.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.