[][src]Struct sibyl::Date

pub struct Date<'e> { /* fields omitted */ }

Represents Oracle DATE

Methods

impl<'e> Date<'e>[src]

pub fn new(year: i16, month: u8, day: u8, env: &'e dyn UsrEnv) -> Self[src]

Constructs new date

pub fn with_time(
    year: i16,
    month: u8,
    day: u8,
    hour: u8,
    min: u8,
    sec: u8,
    env: &'e dyn UsrEnv
) -> Self
[src]

Constructs new date with time

pub fn from_string(txt: &str, fmt: &str, env: &'e dyn UsrEnv) -> Result<Self>[src]

Converts a character string to a date type according to the specified format

Example

use sibyl as oracle;

let env = oracle::env()?;
let date = oracle::Date::from_string("July 4, 1776", "MONTH DD, YYYY", &env)?;
let (y, m, d) = date.get_date();

assert_eq!(1776, y);
assert_eq!(   7, m);
assert_eq!(   4, d);

pub fn from_sysdate(env: &'e dyn UsrEnv) -> Result<Self>[src]

Constructs new date from the client's system clock

Example

use sibyl as oracle;

let env = oracle::env()?;
let date = oracle::Date::from_sysdate(&env)?;
let (y, _m, _d) = date.get_date();

assert!(2019 <= y);

pub fn from_date(from: &Date, env: &'e dyn UsrEnv) -> Result<Self>[src]

Performs a date assignment

pub fn get_date(&self) -> (i16, u8, u8)[src]

Gets the year, month, and day stored in an Oracle date.

pub fn set_date(&mut self, year: i16, month: u8, day: u8)[src]

Changes the date.

pub fn get_time(&self) -> (u8, u8, u8)[src]

Gets the time stored in an Oracle date

pub fn set_time(&mut self, hour: u8, min: u8, sec: u8)[src]

Changes the time

pub fn to_string(&self, fmt: &str) -> Result<String>[src]

Returns a string according to the specified format.

Refer to "TO_DATE" conversion function for a description of format.

Example

use sibyl as oracle;

let env = oracle::env()?;
let date = oracle::Date::new(-1952, 2, 25, &env);
let res = date.to_string("DD-MON-YYYY BC")?;

assert_eq!("25-FEB-1952 BC", res);

pub fn add_days(&self, num: i32) -> Result<Date>[src]

Adds or subtracts days from this date

Example

use sibyl as oracle;

let env = oracle::env()?;
let start = oracle::Date::new(1969, 7, 16, &env);
let end = start.add_days(8)?;
let (y,m,d) = end.get_date();

assert_eq!(1969, y);
assert_eq!(   7, m);
assert_eq!(  24, d);

pub fn add_months(&self, num: i32) -> Result<Date>[src]

Adds or subtracts months from this date.

If the input date is the last day of a month, then the appropriate adjustments are made to ensure that the output date is also the last day of the month. For example, Feb. 28 + 1 month = March 31, and November 30 – 3 months = August 31. Otherwise the result date has the same day component as date.

Example

use sibyl as oracle;

let env = oracle::env()?;
let date = oracle::Date::new(2019, 12, 31, &env);
let date = date.add_months(2)?;
let (y,m,d) = date.get_date();

assert_eq!(2020, y);
assert_eq!(   2, m);
assert_eq!(  29, d);

let date = date.add_months(2)?;
let (y,m,d) = date.get_date();

assert_eq!(2020, y);
assert_eq!(   4, m);
assert_eq!(  30, d);

pub fn compare(&self, other: &Date) -> Result<Ordering>[src]

Compares this date with the other date.

pub fn days_from(&self, other: &Date) -> Result<i32>[src]

Gets the number of days between two dates.

When the number of days between date1 and date2 is computed, the time is ignored.

Example

use sibyl as oracle;

let env = oracle::env()?;
let pearl_harbor = oracle::Date::new(1941, 12, 7, &env);
let normandy_landings = oracle::Date::new(1944, 6, 6, &env);
let days_between = normandy_landings.days_from(&pearl_harbor)?;

assert_eq!(912, days_between);

pub fn month_last_day(&self) -> Result<Date>[src]

Gets the date of the last day of the month in a specified date.

Example

use sibyl as oracle;

let env = oracle::env()?;
let date = oracle::Date::new(2020, 2, 9, &env);
let date = date.month_last_day()?;
let (y,m,d) = date.get_date();

assert_eq!(2020, y);
assert_eq!(   2, m);
assert_eq!(  29, d);

pub fn next_week_day(&self, weekday: &str) -> Result<Date>[src]

Gets the date of the next day of the week after a given date.

Example

The following code example shows how to get the date of the next Monday after April 18, 1996 (a Thursday).

use sibyl as oracle;

let env = oracle::env()?;
let apr18_1996 = oracle::Date::from_string("18-APR-1996", "DD-MON-YYYY", &env)?;
let next_mon = apr18_1996.next_week_day("MONDAY")?;
let next_mon = next_mon.to_string("DD-MON-YYYY")?;

assert_eq!("22-APR-1996", next_mon);

Trait Implementations

impl<'_> ToSql for Date<'_>[src]

impl<'_> ToSqlOut for Date<'_>[src]

fn set_len(&mut self, _new_len: usize)[src]

Called to set the received data length (always less than the initial capacity)

impl<'a> FromSql<'a> for Date<'a>[src]

Auto Trait Implementations

impl<'e> !Send for Date<'e>

impl<'e> !Sync for Date<'e>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]