Вы можете хранить значения Cache в HashMap следующим образом:
HashMap>
Вместо того, чтобы сопоставлять все признаки и понижать объекты признаков, вы можете написать функцию handle()
для вашего trait(CacheTrait)
и затем реализовать ее. на вашем trait objects(MyU32, MyF64 etc.)
. Таким образом, у вас будет отдельная реализация для всех остальных объектов черты, и вам не понадобится ссылка с понижением, потому что вам не нужно будет знать, какой это тип, например:
use std::collections::HashMap;
struct AllCaches {
vectors: HashMap>,
}
struct Cache {
inner: T,
}
struct MyU32 {
inner: u32,
}
struct MyF64 {
inner: f64,
}
// Do custom logic for u32
impl CacheTrait for MyU32 {
fn handle(&self) {
println!("U32");
let data: Vec = Vec::new();
}
}
// Do custom logic for f64
impl CacheTrait for MyF64 {
fn handle(&self) {
println!("F64");
let data: Vec = Vec::new();
}
}
trait CacheTrait {
fn handle(&self);
}
fn main() {
let mut vectors: HashMap>> = HashMap::new();
let cache1: Cache> = Cache {
inner: Box::new(MyU32 { inner: 1u32 }),
};
let cache2: Cache> = Cache {
inner: Box::new(MyF64 { inner: 2f64 }),
};
vectors.insert(1u32, cache1);
vectors.insert(2u32, cache2);
let all_caches = AllCaches { vectors };
all_caches.vectors.iter().for_each(|(_, cache)| {
cache.inner.handle();
});
}
$time = strtotime("2010.12.11");
$final = date("Y-m-d", strtotime("+1 month", $time));
// Finally you will have the date you're looking for.
Просто обновив ответ с простым методом для находки дата после никаких из месяцев. Поскольку лучший отмеченный ответ не дает правильное решение.
<?php
$date = date('2020-05-31');
$current = date("m",strtotime($date));
$next = date("m",strtotime($date."+1 month"));
if($current==$next-1){
$needed = date('Y-m-d',strtotime($date." +1 month"));
}else{
$needed = date('Y-m-d', strtotime("last day of next month",strtotime($date)));
}
echo "Date after 1 month from 2020-05-31 would be : $needed";
?>
strtotime( "+1 month", strtotime( $time ) );
возвращает метку времени, которую можно использовать с функцией даты
Use DateTime::add
.
$start = new DateTime("2010-12-11", new DateTimeZone("UTC"));
$month_later = clone $start;
$month_later->add(new DateInterval("P1M"));
Я использовал clone, потому что add изменяет исходный объект, что может быть нежелательно.