Skip to content

Commit

Permalink
Release version 0.16.3
Browse files Browse the repository at this point in the history
  • Loading branch information
photino committed Dec 1, 2023
1 parent 3e4ac8d commit 0732e92
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 25 deletions.
8 changes: 4 additions & 4 deletions examples/actix-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.15.2"
version = "0.15.3"
features = ["actix"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.16.2"
version = "0.16.3"
features = ["orm-postgres", "view-minijinja"]

[dependencies.zino-derive]
path = "../../zino-derive"
version = "0.13.2"
version = "0.13.3"

[dependencies.zino-model]
path = "../../zino-model"
version = "0.13.2"
version = "0.13.3"
8 changes: 4 additions & 4 deletions examples/axum-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.15.2"
version = "0.15.3"
features = ["axum"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.16.2"
version = "0.16.3"
features = [
"crypto-sm",
"orm-mysql",
Expand All @@ -32,8 +32,8 @@ features = [

[dependencies.zino-derive]
path = "../../zino-derive"
version = "0.13.2"
version = "0.13.3"

[dependencies.zino-model]
path = "../../zino-model"
version = "0.13.2"
version = "0.13.3"
6 changes: 3 additions & 3 deletions examples/dioxus-desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.15.2"
version = "0.15.3"
features = ["dioxus-desktop"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.16.2"
version = "0.16.3"
features = ["orm-sqlite"]

[dependencies.zino-model]
path = "../../zino-model"
version = "0.13.2"
version = "0.13.3"

[dependencies.zino-dioxus]
path = "../../zino-dioxus"
Expand Down
2 changes: 1 addition & 1 deletion zino-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ path = "src/main.rs"
log = "0.4.20"

[dependencies.clap]
version = "4.4.8"
version = "4.4.10"
features = ["color", "derive"]

[dependencies.zino-core]
Expand Down
2 changes: 1 addition & 1 deletion zino-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zino-core"
description = "Core types and traits for zino."
version = "0.16.2"
version = "0.16.3"
rust-version = "1.73"
edition = "2021"
license = "MIT"
Expand Down
57 changes: 54 additions & 3 deletions zino-core/src/datetime/date.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{AvroValue, JsonValue};
use chrono::{format::ParseError, Datelike, Local, NaiveDate};
use crate::{error::Error, AvroValue, JsonValue};
use chrono::{format::ParseError, Datelike, Days, Local, Months, NaiveDate};
use serde::{Deserialize, Serialize, Serializer};
use std::{
fmt,
Expand All @@ -13,6 +13,19 @@ use std::{
pub struct Date(NaiveDate);

impl Date {
/// Attempts to create a new instance.
#[inline]
pub fn try_new(year: i32, month: u32, day: u32) -> Result<Self, Error> {
NaiveDate::from_ymd_opt(year, month, day)
.map(Self)
.ok_or_else(|| {
let message = format!(
"fail to create a date from year: `{year}`, month: `{month}`, day: `{day}`"
);
Error::new(message)
})
}

/// Returns a new instance which corresponds to the current date.
#[inline]
pub fn today() -> Self {
Expand Down Expand Up @@ -122,7 +135,13 @@ impl Date {
/// Returns the day of week starting from 0 (Sunday) to 6 (Saturday).
#[inline]
pub fn day_of_week(&self) -> u8 {
self.0.weekday() as u8
self.iso_day_of_week() % 7
}

/// Returns the ISO day of week starting from 1 (Monday) to 7 (Sunday).
#[inline]
pub fn iso_day_of_week(&self) -> u8 {
(self.0.weekday() as u8) + 1
}

/// Returns `true` if the current year is a leap year.
Expand Down Expand Up @@ -202,6 +221,38 @@ impl Date {
};
Self(date_opt.unwrap_or_default())
}

/// Adds a duration in months to the date.
/// Returns `None` if the resulting date would be out of range.
#[inline]
pub fn checked_add_months(self, months: u32) -> Option<Self> {
self.0.checked_add_months(Months::new(months)).map(Self)
}

/// Subtracts a duration in months from the date.
/// Returns `None` if the resulting date would be out of range.
#[inline]
pub fn checked_sub_months(self, months: u32) -> Option<Self> {
self.0.checked_sub_months(Months::new(months)).map(Self)
}

/// Adds a duration in days to the date.
/// Returns `None` if the resulting date would be out of range.
#[inline]
pub fn checked_add_days(self, days: u32) -> Option<Self> {
self.0
.checked_add_days(Days::new(u64::from(days)))
.map(Self)
}

/// Subtracts a duration in days from the date.
/// Returns `None` if the resulting date would be out of range.
#[inline]
pub fn checked_sub_days(self, days: u32) -> Option<Self> {
self.0
.checked_sub_days(Days::new(u64::from(days)))
.map(Self)
}
}

impl Default for Date {
Expand Down
27 changes: 26 additions & 1 deletion zino-core/src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ impl DateTime {
self.0.second()
}

/// Returns the millisecond number from 0 to 999.
#[inline]
pub fn millisecond(&self) -> u32 {
self.0.timestamp_subsec_millis() % 1000
}

/// Returns the microsecond number from 0 to 999.
#[inline]
pub fn microsecond(&self) -> u32 {
self.0.timestamp_subsec_micros() % 1000
}

/// Returns the nanosecond number from 0 to 999.
#[inline]
pub fn nanosecond(&self) -> u32 {
self.0.timestamp_subsec_nanos() % 1_000_000
}

/// Returns the ISO week number starting from 1.
///
/// The return value ranges from 1 to 53. (The last week of year differs by years.)
Expand All @@ -294,7 +312,13 @@ impl DateTime {
/// Returns the day of week starting from 0 (Sunday) to 6 (Saturday).
#[inline]
pub fn day_of_week(&self) -> u8 {
self.0.weekday() as u8
self.iso_day_of_week() % 7
}

/// Returns the ISO day of week starting from 1 (Monday) to 7 (Sunday).
#[inline]
pub fn iso_day_of_week(&self) -> u8 {
(self.0.weekday() as u8) + 1
}

/// Returns `true` if the current year is a leap year.
Expand Down Expand Up @@ -666,6 +690,7 @@ mod tests {

let date = "2023-11-30".parse::<Date>().unwrap();
let datetime = DateTime::from(date);
assert!(datetime.day_of_week() == 4);
assert_eq!("2023-11-30", datetime.format_date());
assert_eq!("00:00:00", datetime.format_time());
}
Expand Down
15 changes: 14 additions & 1 deletion zino-core/src/datetime/time.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AvroValue, JsonValue};
use crate::{error::Error, AvroValue, JsonValue};
use chrono::{format::ParseError, Local, NaiveTime, Timelike};
use serde::{Deserialize, Serialize, Serializer};
use std::{
Expand All @@ -13,6 +13,19 @@ use std::{
pub struct Time(NaiveTime);

impl Time {
/// Attempts to create a new instance.
#[inline]
pub fn try_new(hour: u32, minute: u32, second: u32) -> Result<Self, Error> {
NaiveTime::from_hms_opt(hour, minute, second)
.map(Self)
.ok_or_else(|| {
let message = format!(
"fail to create a time from hour: `{hour}`, minute: `{minute}`, second: `{second}`"
);
Error::new(message)
})
}

/// Returns a new instance which corresponds to the current time.
#[inline]
pub fn now() -> Self {
Expand Down
4 changes: 2 additions & 2 deletions zino-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zino-derive"
description = "Derived traits for zino."
version = "0.13.2"
version = "0.13.3"
rust-version = "1.73"
edition = "2021"
license = "MIT"
Expand All @@ -21,5 +21,5 @@ syn = "2.0.39"

[dependencies.zino-core]
path = "../zino-core"
version = "0.16.2"
version = "0.16.3"
features = ["orm"]
6 changes: 3 additions & 3 deletions zino-model/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zino-model"
description = "Domain models for zino."
version = "0.13.2"
version = "0.13.3"
rust-version = "1.73"
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -43,7 +43,7 @@ features = ["derive"]

[dependencies.zino-core]
path = "../zino-core"
version = "0.16.2"
version = "0.16.3"
features = [
"orm",
"validator-email",
Expand All @@ -52,4 +52,4 @@ features = [

[dependencies.zino-derive]
path = "../zino-derive"
version = "0.13.2"
version = "0.13.3"
4 changes: 2 additions & 2 deletions zino/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zino"
description = "Next-generation framework for composable applications in Rust."
version = "0.15.2"
version = "0.15.3"
rust-version = "1.73"
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -175,4 +175,4 @@ optional = true

[dependencies.zino-core]
path = "../zino-core"
version = "0.16.2"
version = "0.16.3"

0 comments on commit 0732e92

Please sign in to comment.