Event Time Issue in Ektron calendar - ektron

I created a calendar event with all day selected (10/24/2013) . Then i tried to pull the e.EventStart and e.EventEnd. My expected result was EventStart =10/24/2013 12.00.00 am and
EventEnd= 10/25/2013 12.00.00 am. But what am getting is EventStart =10/24/2013 12.00.00 am and EventEnd= 10/24/2013 12.00.00 am.
The same works fine when I try with e.EventStartUtc and e.EventEndUtc. But I dont want the utc format as I am trying to pull out the ektron time for the users.

If you use the Framework API, the WebEventData class has a property called IsAllDay. You could use this to trigger the display change. For example, you might not want to display start/end times at all if it's an All Day event and just show the date.
If you do need to have particular start/end times for all day events, you can easily extend the Ektron WebEventData object with extension methods.
public static class WebEventExtensions
{
public static DateTime GetDisplayStartDate(this WebEventData webEvent)
{
if (!webEvent.IsAllDay)
return webEvent.EventStart;
return new DateTime(webEvent.EventStart.Year, webEvent.EventStart.Month, webEvent.EventStart.Day);
}
public static DateTime GetDisplayEndDate(this WebEventData webEvent)
{
if (!webEvent.IsAllDay)
return webEvent.EventEnd;
return new DateTime(webEvent.EventEnd.Year, webEvent.EventEnd.Month, webEvent.EventEnd.Day, 23, 59, 59);
}
}
Then those methods will appear on the object.
var eventManager = new WebEventManager();
WebEventData webEvent = eventManager.GetItem(730);
if (webEvent.IsAllDay)
{
// do all-day stuff...
}
var start = webEvent.GetDisplayStartDate();
var end = webEvent.GetDisplayEndDate();

Related

How to set Duration dynamically for ResponseCacheAttribute

I have a .Net Core 3.1 Web Api application and use the ResponseCache attribute on a controller action.
[HttpGet]
[ResponseCache(Location = ResponseCacheLocation.Any, Duration = 30, VaryByQueryKeys = new[] { "id"})]
public string Get([FromQuery] int id)
{...}
While this is working fine with the hardcoded value for Duration, I need to set this dynamically from the config somehow.
I already tried:
Configuring it in Response Caching Middleware, but then it applies to all controller actions.
Deriving from ResponseCacheAttribute does not work, as it's internal.
Is there a simple way to achieve what I want, or do I have to write the whole thing (custom ResponseCacheAtrribute + ResponseCacheFilter + ResponseCacheFilterExecutor) by myself ?
I make a new attribute which inherits from the ResponseCacheAttribute which adds most of what I need. For example -
public class ResponseCacheTillAttribute : ResponseCacheAttribute
{
public ResponseCacheTillAttribute(ResponseCacheTime time = ResponseCacheTime.Midnight)
{
DateTime today = DateTime.Today;
switch (time)
{
case ResponseCacheTime.Midnight:
DateTime midnight = today.AddDays(1).AddSeconds(-1);
base.Duration = (int)(midnight - DateTime.Now).TotalSeconds;
break;
default:
base.Duration = 30;
break;
}
}
}
The Enum looks like
public enum ResponseCacheTime
{
Midnight
}
This allows me to build in specific times that I may need. I haven't fully tested this but confirmed I see the information in the response output.
You should be able to add any arguments or information you need into the attribute.

Calculate difference between two dates with timestamps in Laravel

I have in my table a timestamps with created_at and updated_at
$table->timestamps();
But I want to add another column that calculates the difference between created_at and updated_at in days
Should I do that in SQL or in my controller?
You can do that from within your Eloquent model.
Let's assume your model has the name User.
You can create a computed field by defining an Accessor.
class User extends Model
{
$dates = [
'updated_at',
'created_at'
];
$appends = ['diffInDays'];
public function getDiffInDaysAttribute()
{
if (!empty($this->created_at) && !empty($this->updated_at)) {
return $this->updated_at->diffInDays($this->created_at);
}
}
}
Some explanation
By adding created_at and updated_at to the $dates array, Laravel automatically casts your date values to Carbon.
Now, if you do something like $user->created_at, you don't get the string, but a Carbon instance of that date. This allows you to make some nice date calculations, like the one above.
By adding an Accessor with the getDiffInDaysAttribute function, you can call the days difference via $user->diffInDays like a normal attribute, although it is not on the model.
But if you would now do something like $user->toArray(), the diffInDays attribute will not be available.
To always add the difference in days when you retrieve User data, you can add the field to the $appends array.
That way, the field will always be returned when you retrieve User data via Eloquent.
To have it auto save this value on every update to that model, then you can put this in the model.
public static function boot()
{
parent::boot();
static::updating(function($model) {
$diffInDays = $model->updated_at->diffInDays($model->created_at);
$model->timestamp_difference = $diffInDays;
});
}
timestamp_difference is the name of the DB column that I used, this can be whatever you want it to be.
Use Carbon for count date difference in days.
$to = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $created_at);
$from = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $updated_at);
$diff_in_days = $to->diffInDays($from);

Primefaces - Use an Object in the DefaultScheduleEvent <p:schedule>

I'm using the <p:shecule> and i want to know how can i interact or use this Object data DefaultScheduleEvent.
For example if i want to fill the calendar with more information or save different data than the String title, Date start, date End.
Right now i'm filling the calendar using a for. And it's working fine. But there are more related information that i want to show in the <p:dialog>.
This is the addition information that i want to save/show
for (TimeSheetEntity timeSheetEntity : listaReportesTS) {
String descripcion = timeSheetEntity.getProyectoE().getDescripcionProyecto();
Date fechaInicio = obtFechaHora(timeSheetEntity.getDiaLaboral(), timeSheetEntity.getHoraInicio());
Date fechaFinal = obtFechaHora(timeSheetEntity.getDiaLaboral(), timeSheetEntity.getHoraFin());
eventModel.addEvent(new DefaultScheduleEvent(descripcion, fechaInicio, fechaFinal));
}
How can i do it? and how can i save all this data and get the DefaultScheduleEvent recognize it?
Thank you!
EDIT 1:
I created a new class that extends DefaultScheduleEvent but still no luck. The event is only saved when i enter the title, the start date and the end date. If i enter any other value nothing happens, not even an error in the console.
public class Prueba extends DefaultScheduleEvent{
private AsignacionEntity proyecto;
private TipoActividadEntity actividad;
private boolean horaAlmuerzo;
private String desc;
private String incidente;
private float horasTrabajadas;
public Prueba() {
super();
}
public Prueba(String title, Date startDate, Date endDate) {
super(title, startDate, endDate);
}
//getters and setters
And in the bean:
private Prueba pruebaEvento = new Prueba();
In the view:
<h:outputText for="incidente" value="IM/ALM"/>
<p:inputText id="incidente" value="#{registroBean.pruebaEvento.incidente}" required="false" size="5"/>
Finally i tried with the Object data and set the value from the VO/DTO in the constructor but no luck again.
dse = new DefaultScheduleEvent();
dse.setData(new TimeSheetVO());

NHibernate5: converting dates to local dates when they're persisted without a specific kind

Now that NHibernate 5 is out, I was wondering what's the recommended approach to load dates as local dates when they're persisted as datetime2 in a SQL Server 2016 database. Until now, dates were interpreted as local (so, the properties ended up with the correct values), but now, the behavior has changed and I'm unable to use the LocalDateTime.
Unfortunately, my donmain's behavior relies in getting those dates automatically loaded as local dates...
Any pointers on how to solve this?
Thanks,
Luis
Since I didn't found a way to disable this behavior, I've ended up creating a new type that will simply adjust the format of the data (considering always that it was saved in local format):
public class LocalDateTimeTypeNoThrow : LocalDateTimeType {
public LocalDateTimeTypeNoThrow() {
}
public LocalDateTimeTypeNoThrow(DateTimeSqlType sqlType) : base(sqlType) {
}
public override string Name => "LocalDateTimeNoThrow";
public override void Set(DbCommand st, object value, int index, ISessionImplementor session) {
var dateValue = (DateTime) value;
//removed throwing from here
st.Parameters[index].Value = AdjustDateTime(dateValue);
}
}
If there's a better way, please let me know.
Luis

Apache Wicket DateTextField clear

I have a problem in my DateTextField in Wicket. I want to set it by default to nothing, null, so date can be choosed after someone picks it. But by default it sets value to current day. How to "clear" it so nothing is in this datetextfield? Here is my Datefield code:
DateField date_insert_date_from = new DateField("insert_date_from", new PropertyModel(this, "date")) {
/**
* Format date to yyyy-MM-dd pattern.
*/
#Override
protected DateTextField newDateTextField(String id, PropertyModel dateFieldModel) {
return DateTextField.forDatePattern(id, dateFieldModel, "yyyy-MM-dd");
}
};
form.add(date_insert_date_from);
As #kan says, you need to make sure the modelobject for the datefield is null.
Simple way to do so is:
DateField date_insert_date_from = new DateField("insert_date_from", new Model<Date>(null));
Now, if anyone enters a date into the datefield and submits the form, the Model will contain the chosen date and you can retrieve it by writing:
Date chosenDate = date_insert_date_from.getModelObject();
If you want to use a propertymodel, as you do, you need to make sure the object on which the propertymodel acts (this in your case) has a field capable of holding a date and getter/setter methods for that field.
In your case, this.date should be initialized with null and this should have
public Date getDate()
and
public void setDate(Date date)
methods.