Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 11:14
    djc commented #523
  • 11:14
    djc closed #523
  • 11:14
    djc commented #523
  • 10:23
    Kinrany commented #523
  • 09:48
    omid commented #696
  • 09:23
    omid closed #696
  • 09:23
    omid commented #696
  • 09:21
    omid commented #696
  • 08:55
    omid edited #696
  • 08:06
    omid opened #696
  • May 18 11:40
    fxredeemer opened #695
  • May 17 22:03
    sestrella synchronize #666
  • May 17 20:52
    djc commented #694
  • May 17 20:21
    vriesk opened #694
  • May 17 12:56
    SorenHolstHansen commented #693
  • May 17 12:56
    SorenHolstHansen closed #693
  • May 17 12:56
    SorenHolstHansen commented #693
  • May 17 08:49
    djc commented #693
  • May 17 08:28
    SorenHolstHansen commented #693
  • May 17 05:17
    sestrella synchronize #666
Benno Rice
@jeamland
Hi, I'm looking at #380 / #384 and seeing if I can implement a version of Period that is generic over Datelike + Timelike however the biggest issue there is that it really wants to work off a "DateTimelike" that can do things like work out what a "DateTimelike" + a Duration is.
An idea how I'd go about tweaking things so I had that?
Brandon W Maister
@quodlibetor
@jcdickinson sorry I missed your chat, you should be able to test by using the chrono-tz package for the timezone?
@jeamland are you referring to the issue I mentioned in this comment? https://github.com/chronotope/chrono/pull/384#discussion_r363054371
Benno Rice
@jeamland
@quodlibetor Yep, exactly.
I'm spiking something that ends up moving a bunch of methods around (e.g. .and_time() moves on to Datelike and a lot of .timestamp*() methods move on to a new DateTimelike) but it's fairly drastic.
I think you end up with less churn if you have Period and NaivePeriod. Otherwise you could move a lot of functionality into Datelike/Timelike/DateTimelike or you could do away with Naive* entirely in some way (either by assuming UTC unless otherwise specified or by making the TimeZone inside a Date/Time/DateTime be an Option of some kind).
Brandon W Maister
@quodlibetor
I'd be happy to take a look at WIP PRs for detailed discussion!
I don't want to break backwards compatibility, but I'd be happy to look at things that do break backcompat as part of brainstorming solutions
Michael-J-Ward
@Michael-J-Ward
Any pointers on tracking down the trigger for LocalResult::None => panic!("No such local time")
Brandon W Maister
@quodlibetor
that should mean that you are trying to construct a timestamp within a DST transition, you can use the _opt version of the method you were calling to have chrono return the result, or set RUST_BACKTRACE=1 to figure out where it was being called.
Michael-J-Ward
@Michael-J-Ward
+1, I believe it's from a timestamp being parsed from a 3rd party. The only timestamps created within the app are UTC
Michael-J-Ward
@Michael-J-Ward
RUST_BACKTRACE=1
thread 'main' panicked at 'No such local time', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.11/src/offset/mod.rs:173:34
stack backtrace:
   0: std::panicking::begin_panic
   1: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   2: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   3: <tokio::future::poll_fn::PollFn<F> as core::future::future::Future>::poll
   4: exchange_data_capture::spreader_runner::start_spreader::{{closure}}
   5: <tokio::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll
   6: <tokio::future::poll_fn::PollFn<F> as core::future::future::Future>::poll
   7: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   8: std::thread::local::LocalKey<T>::with
   9: tokio::runtime::enter::Enter::block_on
  10: tokio::runtime::thread_pool::ThreadPool::block_on
  11: tokio::runtime::context::enter
  12: grpc_server::main
Brandon W Maister
@quodlibetor
my guess is that you're calling a chrono method that panics instead of returns an error in 4: exchange_data_capture::spreader_runner::start_spreader::{{closure}}
the fact that chrono inlines many methods cand mean that it doesn't show up in backtraces, I suppose? I haven't seen that much
Jake Vossen
@jakevossen5
Any reason the Sum trait is not implemented for Duration?
I can open up an issue if that is a better place for this
Jake Vossen
@jakevossen5
(I went ahead and opened this: chronotope/chrono#520)
José Miguel Sánchez García
@jmi2k
Hello! Came to ask something
When parsing a time with NaiveTime::parse_from_str, at least hour and minutes are required for it to suceed. I want to parse a time which is expressed only with the hour (9PM), which I think can be widely understood to mean 21:00:00. What is the reason behind not allowing this kind of common notation?
Jake Vossen
@jakevossen5
Lol I am working exactly on this right now
Let me find the issue
Does that fit your requirements?
José Miguel Sánchez García
@jmi2k
I kinda like the second option
Changing function signatures is always messy because it breaks code, and also only one of the returned values would be useful. Adding new functions seems a better idea
Jake Vossen
@jakevossen5
Yeah basically you’ll be able to specify default seconds / minutes.
José Miguel Sánchez García
@jmi2k
However, I think defaulting to zero is a great idea. Can you provide a counter-example of when interpreting missing minutes/seconds as 0 can lead to problems? I can't find any right now.
(also, seconds are already being defaulted to 00 if they are not present)
Jake Vossen
@jakevossen5
I could see a situation where someone wanted to default to 30. At least going off what @quodlibetor said in that issue, we can implement the generic case then offer a function that specifies it defaults to zero. Does that make sense?
I am new to this project so @quodlibetor is probably your go to for more design decisions
José Miguel Sánchez García
@jmi2k
Don't get me wrong: what you suggest is indeed the most sensible, flexible and explicit approach, although IMHO a bit less convenient. But I'm willing to lose that bit of convenience in the name of doing The Right Thing! I've just made what I need in a private fork, and I'll switch back to upstream chrono when it gets implemented! Thanks :)
Jake Vossen
@jakevossen5
Sounds good. I imagine part of it is it is kinda off spec? Maybe someone reading around here knows more, but from my reading of 8601, T01 is not short hand for 01:00:00, it just refers to the general "01" hour. In my head, chrono will have functions that allow you to specify your own defaults, and functions that will default to zero.
José Miguel Sánchez García
@jmi2k
It may be the case, and a pretty good reason not to default to zero so lightly...
Will
@LMJW
Hi all, is it possible to parse time with optional section? Just like in https://stackoverflow.com/questions/51176936/java-8-datetimeformatter-parsing-optional-sections ?
Like HH:MM:[SS] and SS is optional ?
Jake Vossen
@jakevossen5
Yeah there is this GitHub issue that I haven’t really had the time to try and fix it yet chronotope/chrono#528
0x5c
@0x5c
Hello! I've looked though the documentation and it seems that there is no exposed way to get the available precision (0/3/6/9 digits after seconds) of a DateTime. Did I just miss it?
ok-nick
@ok-nick
I'm trying to deserialize a NaiveDateTime, although for some reason it errors with "trailing input". Does deserializing a NaiveDateTime from a String not assume its format is ISO 8601? What are the best ways to get around this?
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=836fac98df345c97cf9241b89c273fa5
ok-nick
@ok-nick
Looked through the code and for some reason the deserializers format is some hardcoded custom format. Not sure why this is done rather than just calling something like parse_from_str internally, or just replicating its behavior?
I'm going to leave an issue on github since this chat is very inactive.
techmindful
@techmindful:privacytools.io
[m]
How do I turn a timestamp integer into a date string with a non-UTC timezone?
Yousuf Jawwad
@debuggerpk
hi guys ... i am trying to convert a utc timestamp to ntp timeformat ... but my test is failing
can somebody please guide me
#[derive(Debug, ByteMe, PartialEq, Eq, Clone, Copy)]
pub struct NtpTimestamp {
  /// 32 bit representation in seconds
  pub seconds: u32,
  /// 32 bit representation after seconds
  pub fraction: u32,
}

/// Basic implentation. Taken from
/// Converts a NTP timestamp to a DateTime
/// https://books.google.com.pk/books?id=x1w4EAAAQBAJ&pg=PA319&lpg=PA319&dq=impl+From%3CNtpTimeStamp%3E+for+DateTime%3CUtc%3E+rust&source=bl&ots=O0MEZZr9fH&sig=ACfU3U1KkmXgxHkjc44EQ1CL1ayo6EqwJA&hl=en&sa=X&ved=2ahUKEwjnzLDLk4f0AhVSRBoKHdkSBUIQ6AF6BAgZEAM#v=onepage&q&f=false
impl From<NtpTimestamp> for DateTime<Utc> {
  fn from(ntp_timestamp: NtpTimestamp) -> Self {
    let seconds = ntp_timestamp.seconds as i64 - PRIME_EPOCH_DELTA as i64;
    let mut nanos = ntp_timestamp.fraction as f64;
    println!("{}", nanos as u32);
    nanos *= 1e9;
    nanos /= 2_f64.powi(32);
    println!("{}", nanos as u32);

    Utc.timestamp(seconds, nanos as u32)
  }
}

/// Convert a DateTime to a NTP timestamp
impl From<DateTime<Utc>> for NtpTimestamp {
  fn from(dt: DateTime<Utc>) -> Self {
    let seconds = dt.timestamp() as i64 + PRIME_EPOCH_DELTA as i64;
    let fraction = dt.nanosecond() as f64;
    let fraction = (fraction * 2_f64.powi(32)) / 1e9;
    println!("{:?}", fraction as u32);

    NtpTimestamp {
      seconds: seconds as u32,
      fraction: fraction as u32,
    }
  }
}

impl NtpTimestamp {
  /// Create an NTP timestamp from a DateTime
  pub fn new(seconds: u32, fraction: u32) -> Self {
    NtpTimestamp { seconds, fraction }
  }

  /// Get the current NTP timestamp
  pub fn now() -> Self {
    let now = Utc::now();
    NtpTimestamp::from(now)
  }
}
suchowo
@suchowo
How can i check if a date is older than another one?
for example 12/1/2022 is older than 11/1/2022
btw im using utc
Melg8
@melg8:matrix.org
[m]
Hi, i'm new to Rust, and it's policies, i have a question. Do chrono really need num-iter = { version = "0.1.35", default-features = false } dependency? from what i saw it used in tests for calls like range_inclusive(1u32, 366). Can it be just replaced with 1u32..=366 syntax and get rid of it? or what consideration i am missing?
Eduardo Pinho
@Enet4
@melg8:matrix.org I suspect it's because the inclusive range syntax is not available in the minimum supported version of the library. That could change with an eventual update. But an extra dependency isn't much to worry about.