in my database the time someone has worked is stored in a certain amount of minutes. In my report I list those minutes in the format HH:MM. I do this by making use of the following function:
Function (numberVar numberToBeConverted)
local TimeVar result;
local StringVar hh := ToText((Truncate( numberToBeConverted ) / 60), "0");
local StringVar mm := ToText((Truncate( Abs(numberToBeConverted) ) mod 60), "00");
local StringVar ss := '00';
Local StringVar t:= hh + ":" + mm + ":" + ss;
if istime (t)
then result := TimeValue (tijd)
else result := TimeValue ("23:59:59");
result
I would like to preserve the datatype (time) but would like to be able to list duration longer then 24 hours (i.e. a workweek).
is this possible?
thanks
Unfortunately, CR's time format doesn't support what you want to do. Try my ElapsedTime() custom function, instead.
** edit **
If the field returns the # of seconds, you could make use of its Display String formula. Right click the field, choose 'Format Field...', then the 'Common' tab, then the button to the right of the 'Display String:' text; enter the following text:
//CurrentFieldValue assumed to be in seconds
ElapsedTime(CurrentFieldValue)
With this approach, you'll be able to have the formatting that you desire and still be able to use the field itself in calculations.
Related
I would like to define a datetime type variable that is a result of a simple arithmetic operation between datetime type variables.
I've defined:
datetime duration = ( TimeCurrent() - OrderOpenTime() );
datetime TmStop = StringToTime( "1970.01.01 16:00" );
but when I call it in some other arithmetic operation or generally in code like this
ExitBuy_H1 = ( duration > TmClose && ...
or this
text[3]= "Duration: " + TimeToStr( duration, TIME_MINUTES );
it doesn't work.
TmStop instead works fine.
Does anyone know why?
datetime is a simple integer, number of seconds passed since 1970.01.01 00:00. duration in your example is also in seconds, even though it is datetime formated, when you need it in minutes, divide by 60. TmClose from your example means 16*60*60 seconds and you can compare that integer with any other int of course, but what might be the reason for that?
if you hold you position more then 16 hours, then duration > TmClose is true. if you want to convert difference in seconds (duration) into time, then you will have time converted from 1970.01.01 00:00 + duration seconds.
Anyway it is not clear what is your goal in doing this calculations? if you want to make sure that you hold that particular position more then x hours, then simple bool holdMoreThanXHours = TimeCurrent()-OrderOpenTime()>x*PeriodSeconds(PERIOD_H1), and do not forget to reselect each ticket if you have several ones in open
Fact A) the code, as-is, absolutely out of any question works.
//+------------------------------------------------------------------+
//| Test_StackOverflow.mq4 |
//+------------------------------------------------------------------+
#property strict
void OnStart() {
datetime duration = ( TimeCurrent() - OrderOpenTime() );
string txt = "Duration: " + TimeToStr( duration, TIME_MINUTES );
}
//+------------------------------------------------------------------+
0 error(s), 0 warning(s), compile time: 2000 msec 1 1
Fact B) the full MCVE-context of the code, as-is, is missing.
StackOverflow requires users to post a complete MCVE-representation of the problem. This requirement was not met in the original post.
While the datetime and int data-types are mutually interchangeable, the problem does not seem to be hidden in this intrinsic "duality" of a value representation, but must be somewhere else.
The main suspects for Why? are:
variable definition was masked by another variable having the same name
variable scope-of-definition was exceeded ( asking a variable outside of it's scope )
db.Pool-operations were not preceded by OrderSelect()
I'm stuck with how to process the results of a query before sending it to Jinja2 for rendering on the browser.
I'm developing the app on Google App Engine for Python.
I store the amount of working hours in a "calendar" entity as amount of seconds, this will then allow me to make a number of calculations about time. The problem I have is how to modify the result of the query, so that I pass to the Jinja2 html file the time not in seconds (Integer) but as HH:MM (String)
My models.py file is as follows:
'calendars_list': calendars_list,
class Calendar(ndb.Model):
wtd1 = ndb.IntegerProperty() # Working seconds day 1
wtd2 = ndb.IntegerProperty() # " 2
wtd3 = ndb.IntegerProperty() # " 3
wtd4 = ndb.IntegerProperty() # " 4
wtd5 = ndb.IntegerProperty() # " 5
wtd6 = ndb.IntegerProperty() # " 6
wtd7 = ndb.IntegerProperty() # " 7
In the main request handler I get the query (after defining ancestor etc) and need to change the seconds to HH:MM before rendering in the browser.
calendars_query = models.Calendar.query(ancestor = get_calendars_key()).order(models.Calendar.calendar_id)
calendars_list = calendars_query.fetch(10)
# Now: convert working times per day (sec) to HH:MM
for calendar in calendars_list:
calendar.wtd1 = format_as_HHMM(calendar.wtd1)
--> Gives an error: calendar.wtd1 needs to be an integer, can't be a string
template_values = {
'calendars_list': calendars_list,
}
template = JINJA_ENVIRONMENT.get_template('calendars.html')
self.response.write(template.render(template_values))
As shown above, when I modify the calendar.wtd1 element to change it from say 3600 to 01:00 I get an error because it needs to be an integer.
Any ideas how I can change the code so that I can process the query results appropriately?
Thanks!
The issue with your code is that you try to assign a value that is not an integer to a ndb.IntegerProperty().
Replace
calendar.wtd1 = format_as_HHMM(calendar.wtd1)
with
calendar.wtd1_HHMM = format_as_HHMM(calendar.wtd1)
and use calendar.wtd1_HHMM in the template and it will probably work out nicely.
Edit:
If you prefer to convert from integer to HH:mm in the template as part of the presentation logic you could do that easily by writing the conversion function and register it as a filter as explained in the documentation - writing filters
When it comes to functions for doing the conversion you are in luck:
Python: convert seconds to hh:mm:ss
I'm developing a custom validator of a date input in my workflow form and I get a null after parsing a date this is what I done:
// check dates can be parsed
str_expiryDate = field.form.prop_wfbxTestWorkFlow_NfDate.value;
console.log("Non conformite"+str_expiryDate);
str_reminderDate = field.form.prop_bpm_workflowDueDate.value;
console.log("echeance"+str_reminderDate);
Alfresco.logger.warn("Expiry Date: " + str_expiryDate + " | Reminder Date: " + str_reminderDate);
d_expiryDate = Date.parse(str_expiryDate);
console.log("nfDate"+str_expiryDate);
d_reminderDate = Date.parse(str_reminderDate);
console.log("Date echéance"+d_reminderDate);
and then i get this in console:
Non conformite2013-06-21T00:00:00.000+01:00 echeance2013-06-09T00:00:00.000+01:00
nfDatenull
Date echéancenull
How I can parse these two dates and then compare it? .thanks
Use Alfresco.util.fromISO8601(date)
According to the client-api docs
Convert an ISO8601 date string into a JavaScript native Date object
You are parsing the "value" of a date, not the date itself.
The best way to compare is, imho, using the format YYYYMMDD, and than compare it as a number.
Something like this (there is sure a far more elegant way to do that, but at this time it's the only one that got me):
var indexDate=str_expiryDate.indexOf("-");
var dayDate=str_expiryDate.substring(0, 2);
var monthDate=str_expiryDate.substring(3, 5);
var yearDate=fromData.substring(6, str_expiryDate.length+1);
int dataNew=yearDate+monthDate+dayDate;
and than compare the two dates value.
Obviously check if the index value are correct, I didn't double checked them.
Hope il helps.
So i have a bar graph in crystal reports. On this graph i have a data label attached to each of the graphs that displays the value of the graph in seconds, which appears like so:
What i would like to do is format this data-label into a time formatting. So for each bar in the graph it would have the data-label appear in the following format:
HH:MM:SS.
i am able to get the time formatting to appear using the following formula:
local NumberVar Sec;
local NumberVar ss;
local NumberVar mm;
local NumberVar hh;
local StringVar SSS;
local StringVar MMM;
Sec := Sum ({GetAlarmSummaryDataSet2Response/GetAlarmSummaryDataSet2Result/Items/AlarmSummaryItem2.StopTime}, {GetAlarmSummaryDataSet2Response/GetAlarmSummaryDataSet2Result/Items/AlarmSummaryItem2.Section}) ;
hh := Int (Sec/3600);
mm :=Int ((Sec/60)- (60* Int(Sec/3600 )));
If mm<10 then MMM := "0" & ToText (mm,0);
If mm>9 Then MMM := ToText(mm,0) ;
ss :=Sec-(3600 * hh ) - (60 * mm ) ;
If ss<10 then SSS := "0" & ToText (ss,0);
If ss>9 Then SSS := ToText(ss,0) ;
ToText ( hh,0) & ":" & MMM & ":" & SSS
But what i am unsure of is how to implement this formula onto a data label.
Any help or suggestions are greatly appreciated.
Thank you
You can choose to display the group name, and you can display and format the summarized value calculated by the chart, but you can't provide a custom formula. It just isn't possible using the chart library in CR XI.
My eventual workaround for this problem:
Modify the value formula to eliminate the aggregate function. (This is necessary because Crystal won't allow an aggregate function in a group name field -- see #2.)
For the group name, specify a formula with the text you want to display in the riser. Include both the label and the formatted value, separated by Chr(13) & Chr(10) to place them on separate lines.
Configure the riser to display the label, not the value.
To apply this to your problem you'd need to make these changes:
Eliminate the aggregate function. Of course I don't know if this will be possible using your setup. Perhaps if you're using a DBMS you could use a SQL command or a stored procedure to calculate the sum before the data reaches Crystal.
Print the label and value together, either on the riser or the X-axis.
If that's not good enough for your application, you might consider CRChart, a commercial replacement which tries to address the sometimes-crippling limitations of Crystal's chart library. (I thought it was too pricey.) I think the #APPEND_DATATEXT macro would let you place a custom value on a riser, but you'd still need to move the summary to the server.
Im trying to compare Calendars with JPA2. The query looks somewhat like that:
TypedQuery<X> q = em.createQuery("select r from Record r where r.calendar= :calendar", X.class);
Calendar c = foo(); // setting fields and stuff
q.setParameter("calendar", c);
This, however, compares the date + time. I want to know if MM:DD:YYYY is equal and do not care about the time. Is there a nice way to do that in JPA2 or do I have to create a native query?
I tried setting HH:MM:SS:... to zero before saving it in the db but I don't know if this is very wise, regarding time zones and daylight saving and stuff.
q.setParameter("calendar", c, TemporalType.DATE)
You can pass the TemporalType.DATE to setParameter method to truncate the date+time.
There is no mention of DateTime functions allowing to do that in the spec of JPQL, but you could always cheat and do
select r from Record r where r.calendar >= :theDayAtZeroOClock and r.calendar < :theDayAfterAtZeroOClock
Mysql and H2 compatible comparison of dates ignoring time part:
`#Query("SELECT DISTINCT s " +
"FROM Session s " +
"JOIN s.movie m " +
"WHERE m.id = :movie AND CAST(s.time AS date) = CAST(:date AS date) " +
"ORDER BY s.time")
List<Session> getByMovieAndDate(#Param("movie") Long movie, #Param("date") LocalDateTime date);`
When using an Oracle database, you can use the trunc function in your JPQL query, e.g.:
TypedQuery<X> q = em.createQuery("select r from Record r where trunc(r.calendar) = trunc(:calendar)", X.class);
See also https://cirovladimir.wordpress.com/2015/05/18/jpa-trunc-date-in-jpql-query-oracle/
I had to use date_trunc on the where clause:
TypedQuery<X> q = em.createQuery("select r from Record r where date_trunc('day',r).calendar= :calendar", X.class);
Calendar c = foo(); // setting fields and stuff
q.setParameter("calendar", c, TemporalType.DATE);
In Hibernate 6 and above, you can use date_trunc(text, timestamp) to truncate the timestamp more precisely, for example:
date_trunc('hour', timestamp) to truncate the timestamp up to the hour (no minutes and no seconds).