Struct warlocks_cauldron::Datetime
source · pub struct Datetime(pub Locale);Expand description
Struct for generating data related to the date and time
Tuple Fields§
§0: LocaleImplementations§
source§impl Datetime
impl Datetime
sourcepub fn bulk_create_datetimes<Tz: TimeZone>(
date_start: DateTime<Tz>,
date_end: DateTime<Tz>,
delta: Duration
) -> Vec<DateTime<Tz>> ⓘ
pub fn bulk_create_datetimes<Tz: TimeZone>(
date_start: DateTime<Tz>,
date_end: DateTime<Tz>,
delta: Duration
) -> Vec<DateTime<Tz>> ⓘ
Bulk create datetime structs
This method creates list of datetime objects from
date_start to date_end
return example: vec![DateTime, ]
Arguments
date_start- Begin of the rangedate_end- End of the rangedelta- Range delimetr
sourcepub fn periodicity(&self) -> &str
pub fn periodicity(&self) -> &str
Get a random periodicity string.
return example: Periodicity
sourcepub fn year(minimum: i32, maximum: i32) -> i32
pub fn year(minimum: i32, maximum: i32) -> i32
Generate a random year
return example: 2013
Arguments
minimum- Minimum valuemaximum- Maximum value
sourcepub fn day_of_week(&self, abbr: bool) -> &str
pub fn day_of_week(&self, abbr: bool) -> &str
sourcepub fn date(start: i32, end: i32) -> NaiveDate
pub fn date(start: i32, end: i32) -> NaiveDate
Generate random naive date
return example: NaiveDate
Arguments
start- Minimum value of yearend- Maximum value of year
Examples found in repository?
examples/simple.rs (line 9)
3 4 5 6 7 8 9 10 11 12 13 14 15 16
fn main() {
// A common option for most providers
let complex = ComplexProvider::new(Locale::EN);
println!("Person: {}", complex.person.full_name(None, false));
println!("Telephone: {}", complex.person.telephone(None));
println!("Address: {}", complex.address.full_address());
println!("Birthday: {}", Datetime::date(1940, 2000));
println!("Weight: {} kg", Person::weight(30, 90));
println!("Height: {} m", Person::height(1.5, 2.0));
// But you can also use single providers
let russian_person = Person(Locale::RU);
println!("Their Russian friend: {}", russian_person.full_name(None, false));
}sourcepub fn formatted_date(&self, fmt: Option<&str>, start: i32, end: i32) -> String
pub fn formatted_date(&self, fmt: Option<&str>, start: i32, end: i32) -> String
Generate random date as string
return example: Formatted date
Arguments
fmt- The format of date, if None then use standard accepted in the current localestart- Minimum value of yearend- Maximum value of year
sourcepub fn formatted_time(&self, fmt: Option<&str>) -> String
pub fn formatted_time(&self, fmt: Option<&str>) -> String
Generate string formatted time
return example: formatted time
Arguments
fmt- The format of time, if None then use standard accepted in the current locale
sourcepub fn day_of_month() -> i32
pub fn day_of_month() -> i32
Generate a random day of month, from 1 to 31
return example: 13
sourcepub fn timezone(region: Option<TimezoneRegion>) -> &'static str
pub fn timezone(region: Option<TimezoneRegion>) -> &'static str
sourcepub fn gmt_offset() -> &'static str
pub fn gmt_offset() -> &'static str
Get a random GMT offset value
return example: UTC +13:00
sourcepub fn datetime(start: i32, end: i32) -> DateTime<Utc>
pub fn datetime(start: i32, end: i32) -> DateTime<Utc>
Generate random datetime
return example: DateTime
Arguments
start- Minimum value of yearend- Maximum value of year
Examples found in repository?
examples/datagen.rs (line 12)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
fn main() {
println!("Address: {}", Address(Locale::EN).full_address());
println!("IMEI: {}", Code::imei());
println!("Mnemonic Phrase: {}", Cryptographic::mnemonic_phrase());
// start, end
println!("Datetime: {}", Datetime::datetime(1984, 2077));
println!("Filename: {}", File::file_name(None));
// scheme, tld, subdomains
println!("DSN: {}", Development::dsn(Some(DSNType::POSTGRES), Some(TLDType::CCTLD), Some(vec!["shop", "admin"])));
println!("Mac: {}", Internet::mac());
println!("Company: {}", Finance(Locale::EN).company());
println!("Drink: {}", Food(Locale::EN).drink());
println!("Manufacturer: {}", Hardware::manufacturer());
// sequence, length
println!("Choice: {:?}", Choice::pick(&vec!["a", "b", "c"], 5));
println!("Unique choice: {:?}", Choice::pick_unique(&vec!["a", "a", "b", "c"], 5));
// anything hashable object
println!("Increment a=1: {}", Numeric::increment("a"));
println!("Increment a+1: {}", Numeric::increment("a"));
println!("Increment 1=1: {}", Numeric::increment(1));
println!("Increment a+1: {}", Numeric::increment("a"));
println!("Project path: {}", Path::new(PlatformType::detect()).project_dir());
println!("Card struct: {:?}", Payment::credit_card());
// gender, reverse fullname
println!("Fullname: {}", Person(Locale::EN).full_name(Some(Gender::MALE), false));
println!("Telephone: {}", Person(Locale::EN).telephone(None));
println!("Username: {}", Person::username(Some("C.U.l.d"), Some((666, 777))));
// length of sequence
println!("DNA sequence: {}", Science::dna_sequence(10));
// words count
println!("Words: {:?}", Text(Locale::EN).words(5));
// None or Some(locale) for random or locale get transport code
println!("USA transport code: {}", Transport::vehicle_registration_code(Some(Locale::EN)));
}sourcepub fn formatted_datetime(&self, fmt: Option<&str>, start: i32, end: i32) -> String
pub fn formatted_datetime(&self, fmt: Option<&str>, start: i32, end: i32) -> String
Generate datetime string in human readable format
return example: formatted datetime
Arguments
fmt- The format of datetime, if None then use standard accepted in the current localestart- Minimum value of yearend- Maximum value of year