Tloop- compare hour with a value

Six Stars

Tloop- compare hour with a value

Hi
I need the twaitforfile activity component to run until 4.pm, so I’m using the below condition coded in tloop component ( which is, trying to compare the current hour with a value) but I’m getting into various issues, any help is appreciated.
Bigdecimal((TalendDate.getdate(“HH”)).compareTo(16) == -1

Thanks
Mj
Tags (1)

Accepted Solutions
Ten Stars

Re: Tloop- compare hour with a value

You want to run ... from startime : 05:00 until 16:30

 

in tLoop change loop type from FOR into a WHILE,

next copypaste this into condition:

routines.TalendDate.parseDate("HH:mm:ss",routines.TalendDate.getDate("HH:mm:ss") ).before(routines.TalendDate.parseDate("HH:mm:ss", "16:30:00")) 

you can leave the int i=0 and int++ as is...

 

If you want to poll every second... connect via iterate a tSleep.

I've tested above solution and it works! 

If not the case I really dont get what you trying to achieve... 

 

 

 


All Replies
Ten Stars

Re: Tloop- compare hour with a value

Bigdecimal((TalendDate.getdate(“HH”)).compareTo(  BigDecimal.valueOf(16)  )
Forteen Stars TRF
Forteen Stars

Re: Tloop- compare hour with a value

Or this one without conversion:
(TalendDate.getdate(“HH”)).equals("16")
Should work.

TRF
Six Stars

Re: Tloop- compare hour with a value

Hi 

Thanks for responding, I tried that command, below is the exact command i used, actually my job may start around 8 and it has to run until 4.00 PM, with some sleep time in between. so i'm checking the current hour and minutes. for testing purpose i used a different time here, 

 

 

(Bigdecimal((TalendDate.getdate("HH")).compareTo(Bigdecimal.valueof(10)) == -1 || Bigdecimal((TalendDate.getdate("HH")).compareTo(Bigdecimal.valueof(10)) == 0)))&&(Bigdecimal((TalendDate.getdate("mm")).compareTo(Bigdecimal.valueof(35)) == -1)  || (Bigdecimal((TalendDate.getdate("mm")).compareTo(Bigdecimal.valueof(35)) == 0)))

but the job is failing with error

 

	- The method getdate(String) is undefined for the type TalendDate
	- Bigdecimal cannot be resolved

 

Ten Stars

Re: Tloop- compare hour with a value

I put this in a tJava component and run this code.


Date x = routines.TalendDate.parseDate("HH:mm:ss", "12:00:00"); Date y = routines.TalendDate.parseDate("HH:mm:ss", "14:00:00"); System.out.println(y.after(x));

This is more elegant

Six Stars

Re: Tloop- compare hour with a value

Sorry, not sure, how can i use this in the tloop?

Six Stars

Re: Tloop- compare hour with a value

Hi
I have thought about the .equals solution, but it won’t work because, I want the job to run until the current time is less than or equal to 4 , that’s why I opted for the CompareTo operator.....

Any other ideas please

Thanks
MJ
Ten Stars

Re: Tloop- compare hour with a value

You want to run ... from startime : 05:00 until 16:30

 

in tLoop change loop type from FOR into a WHILE,

next copypaste this into condition:

routines.TalendDate.parseDate("HH:mm:ss",routines.TalendDate.getDate("HH:mm:ss") ).before(routines.TalendDate.parseDate("HH:mm:ss", "16:30:00")) 

you can leave the int i=0 and int++ as is...

 

If you want to poll every second... connect via iterate a tSleep.

I've tested above solution and it works! 

If not the case I really dont get what you trying to achieve... 

 

 

 

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.