Tloop- compare hour with a value

Highlighted
Seven 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

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)  )
Fifteen Stars TRF
Fifteen Stars

Re: Tloop- compare hour with a value

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

TRF
Seven 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

Seven Stars

Re: Tloop- compare hour with a value

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

Seven 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... 

 

 

 

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

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

Download