mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-01-13 16:03:22 -05:00
fix a couple time problems
* CameraDayKey::bounds (used to generate the start and end times of days in the returned JSON) returned UTC, not matching what recordings were mapped into that day. So fetching a day with its given bounds would return something different. Test and fix it. * Several time-related tests weren't calling testutil::init(), so they weren't fixing the time zone to the expected America/Los_Angeles. If the machine time is set to something else, they would break.
This commit is contained in:
parent
bbe04f909c
commit
2bdb2eca5d
14
src/db.rs
14
src/db.rs
@ -323,8 +323,9 @@ impl CameraDayKey {
|
||||
|
||||
pub fn bounds(&self) -> Range<recording::Time> {
|
||||
let mut my_tm = time::strptime(self.as_ref(), "%Y-%m-%d").expect("days must be parseable");
|
||||
let start = recording::Time(my_tm.to_timespec().sec * recording::TIME_UNITS_PER_SEC);
|
||||
my_tm.tm_utcoff = 1; // to the time crate, values != 0 mean local time.
|
||||
my_tm.tm_isdst = -1;
|
||||
let start = recording::Time(my_tm.to_timespec().sec * recording::TIME_UNITS_PER_SEC);
|
||||
my_tm.tm_hour = 0;
|
||||
my_tm.tm_min = 0;
|
||||
my_tm.tm_sec = 0;
|
||||
@ -1577,6 +1578,17 @@ mod tests {
|
||||
assert_eq!(0, m.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_day_bounds() {
|
||||
testutil::init();
|
||||
assert_eq!(CameraDayKey(*b"2017-10-10").bounds(), // normal day (24 hrs)
|
||||
recording::Time(135685692000000) .. recording::Time(135693468000000));
|
||||
assert_eq!(CameraDayKey(*b"2017-03-12").bounds(), // spring forward (23 hrs)
|
||||
recording::Time(134037504000000) .. recording::Time(134044956000000));
|
||||
assert_eq!(CameraDayKey(*b"2017-11-05").bounds(), // fall back (25 hrs)
|
||||
recording::Time(135887868000000) .. recording::Time(135895968000000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_version() {
|
||||
testutil::init();
|
||||
|
@ -529,10 +529,11 @@ impl Segment {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use testutil::TestDb;
|
||||
use testutil::{self, TestDb};
|
||||
|
||||
#[test]
|
||||
fn test_parse_time() {
|
||||
testutil::init();
|
||||
let tests = &[
|
||||
("2006-01-02T15:04:05-07:00", 102261550050000),
|
||||
("2006-01-02T15:04:05:00001-07:00", 102261550050001),
|
||||
@ -550,11 +551,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_format_time() {
|
||||
testutil::init();
|
||||
assert_eq!("2006-01-02T15:04:05:00000-08:00", format!("{}", Time(102261874050000)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_display_duration() {
|
||||
testutil::init();
|
||||
let tests = &[
|
||||
// (output, seconds)
|
||||
("0 seconds", 0),
|
||||
@ -577,6 +580,7 @@ mod tests {
|
||||
/// Tests encoding the example from design/schema.md.
|
||||
#[test]
|
||||
fn test_encode_example() {
|
||||
testutil::init();
|
||||
let mut e = SampleIndexEncoder::new();
|
||||
e.add_sample(10, 1000, true);
|
||||
e.add_sample(9, 10, false);
|
||||
@ -592,6 +596,7 @@ mod tests {
|
||||
/// Tests a round trip from `SampleIndexEncoder` to `SampleIndexIterator`.
|
||||
#[test]
|
||||
fn test_round_trip() {
|
||||
testutil::init();
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct Sample {
|
||||
duration_90k: i32,
|
||||
@ -624,6 +629,7 @@ mod tests {
|
||||
/// TODO: test and fix overflow cases.
|
||||
#[test]
|
||||
fn test_iterator_errors() {
|
||||
testutil::init();
|
||||
struct Test {
|
||||
encoded: &'static [u8],
|
||||
err: &'static str,
|
||||
@ -657,6 +663,7 @@ mod tests {
|
||||
/// This is a simpler case; all sync samples means we can start on any frame.
|
||||
#[test]
|
||||
fn test_segment_clipping_with_all_sync() {
|
||||
testutil::init();
|
||||
let mut encoder = SampleIndexEncoder::new();
|
||||
for i in 1..6 {
|
||||
let duration_90k = 2 * i;
|
||||
@ -674,6 +681,7 @@ mod tests {
|
||||
/// Half sync frames means starting from the last sync frame <= desired point.
|
||||
#[test]
|
||||
fn test_segment_clipping_with_half_sync() {
|
||||
testutil::init();
|
||||
let mut encoder = SampleIndexEncoder::new();
|
||||
for i in 1..6 {
|
||||
let duration_90k = 2 * i;
|
||||
@ -690,6 +698,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_segment_clipping_with_trailing_zero() {
|
||||
testutil::init();
|
||||
let mut encoder = SampleIndexEncoder::new();
|
||||
encoder.add_sample(1, 1, true);
|
||||
encoder.add_sample(1, 2, true);
|
||||
@ -704,6 +713,7 @@ mod tests {
|
||||
/// This takes a fast path which skips scanning the index in `new()`.
|
||||
#[test]
|
||||
fn test_segment_fast_path() {
|
||||
testutil::init();
|
||||
let mut encoder = SampleIndexEncoder::new();
|
||||
for i in 1..6 {
|
||||
let duration_90k = 2 * i;
|
||||
@ -718,6 +728,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_segment_fast_path_with_trailing_zero() {
|
||||
testutil::init();
|
||||
let mut encoder = SampleIndexEncoder::new();
|
||||
encoder.add_sample(1, 1, true);
|
||||
encoder.add_sample(1, 2, true);
|
||||
|
Loading…
Reference in New Issue
Block a user