Struct oracle::sql_type::Timestamp

source ·
pub struct Timestamp { /* private fields */ }
Expand description

Oracle-specific Datetime data type

This struct doesn’t have arithmetic methods and they won’t be added to avoid reinventing the wheel. If you need methods such as adding an interval to a timestamp, enable chrono feature and use chrono::Date, chrono::DateTime, chrono::naive::NaiveDate or chrono::naive::NaiveDateTime instead.

§Examples

// Create a timestamp.
let ts1 = Timestamp::new(2017, 8, 9, 11, 22, 33, 500000000);

// Convert to string.
assert_eq!(ts1.to_string(), "2017-08-09 11:22:33.500000000");

// Create a timestamp with time zone (-8:00).
let ts2 = Timestamp::new(2017, 8, 9, 11, 22, 33, 500000000).and_tz_hm_offset(-8, 0);

// Convert to string.
assert_eq!(ts2.to_string(), "2017-08-09 11:22:33.500000000 -08:00");

// Create a timestamp with precision
let ts3 = Timestamp::new(2017, 8, 9, 11, 22, 33, 500000000).and_prec(3);

// The string representation depends on the precision.
assert_eq!(ts3.to_string(), "2017-08-09 11:22:33.500");

// Precisions are ignored when intervals are compared.
assert_eq!(ts1, ts3);

// Create a timestamp from string.
let ts4: Timestamp = "2017-08-09 11:22:33.500 -08:00".parse()?;

// The precision is determined by number of decimal digits in the string.
assert_eq!(ts4.precision(), 3);

Fetch and bind interval values.

let conn = Connection::connect("scott", "tiger", "")?;

// Fetch Timestamp
let sql = "select TIMESTAMP '2017-08-09 11:22:33.500' from dual";
let ts = conn.query_row_as::<Timestamp>(sql, &[])?;
assert_eq!(ts.to_string(), "2017-08-09 11:22:33.500000000");

// Bind Timestamp
let sql = "begin \
             :outval := :inval + interval '+1 02:03:04.5' day to second; \
           end;";
let mut stmt = conn.statement(sql).build()?;
stmt.execute(&[&OracleType::Timestamp(3), // bind null as timestamp(3)
               &ts, // bind the ts variable
              ])?;
let outval: Timestamp = stmt.bind_value(1)?; // get the first bind value.
// ts + (1 day, 2 hours, 3 minutes and 4.5 seconds)
assert_eq!(outval.to_string(), "2017-08-10 13:25:38.000");

Implementations§

source§

impl Timestamp

source

pub fn new( year: i32, month: u32, day: u32, hour: u32, minute: u32, second: u32, nanosecond: u32 ) -> Timestamp

Creates a timestamp.

Valid values are:

argumentvalid values
year-4713 to 9999
month1 to 12
day1 to 31
hour0 to 23
minute0 to 59
second0 to 59
nanosecond0 to 999,999,999
source

pub fn and_tz_offset(&self, offset: i32) -> Timestamp

Creates a timestamp with time zone.

offset is time zone offset seconds from UTC.

source

pub fn and_tz_hm_offset( &self, hour_offset: i32, minute_offset: i32 ) -> Timestamp

Creates a timestamp with time zone.

hour_offset and minute_offset are time zone offset in hours and minutes from UTC. All arguments must be zero or positive in the eastern hemisphere. They must be zero or negative in the western hemisphere.

source

pub fn and_prec(&self, precision: u8) -> Timestamp

Creates a timestamp with precision.

The precision affects text representation of Timestamp. It doesn’t affect comparison.

source

pub fn year(&self) -> i32

Returns the year number from -4713 to 9999.

source

pub fn month(&self) -> u32

Returns the month number from 1 to 12.

source

pub fn day(&self) -> u32

Returns the day number from 1 to 31.

source

pub fn hour(&self) -> u32

Returns the hour number from 0 to 23.

source

pub fn minute(&self) -> u32

Returns the minute number from 0 to 59.

source

pub fn second(&self) -> u32

Returns the second number from 0 to 59.

source

pub fn nanosecond(&self) -> u32

Returns the nanosecond number from 0 to 999,999,999.

source

pub fn tz_hour_offset(&self) -> i32

Returns hour component of time zone.

source

pub fn tz_minute_offset(&self) -> i32

Returns minute component of time zone.

source

pub fn precision(&self) -> u8

Returns precision

source

pub fn with_tz(&self) -> bool

Returns true when the timestamp’s text representation includes time zone information. Otherwise, false.

source

pub fn tz_offset(&self) -> i32

Returns total time zone offset from UTC in seconds.

Trait Implementations§

source§

impl Clone for Timestamp

source§

fn clone(&self) -> Timestamp

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Timestamp

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Timestamp

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromSql for Timestamp

source§

impl FromStr for Timestamp

§

type Err = ParseOracleTypeError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for Timestamp

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToSql for Timestamp

source§

fn oratype(&self, _conn: &Connection) -> Result<OracleType>

source§

fn to_sql(&self, val: &mut SqlValue<'_>) -> Result<()>

source§

impl ToSqlNull for Timestamp

source§

impl Copy for Timestamp

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> RowValue for T
where T: FromSql,

source§

fn get(row: &Row) -> Result<T, Error>

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.