martindstone / pagerduty-cli

A command line interface for PagerDuty
MIT License
91 stars 13 forks source link

schedule:render date format #24

Closed sdenef-adeo closed 2 years ago

sdenef-adeo commented 2 years ago

Hello,

I tried to update all schedule spans over a timeslot. I used the schedule:render command to get the spans.

Example:

$> pd schedule:render -i P999999 --since=2022-01-23T10:00:00.000Z --until=2022-02-07T08:00:00.000Z --filter "User name=Doe" --output=csv                       
Getting schedule P999999... done
Start,End,Duration,User id,User name
"24/01/2022, 09:00:00","28/01/2022, 18:00:00","4d 9h  ","PWWWWWW","John Doe"
"31/01/2022, 09:00:00","04/02/2022, 18:00:00","4d 9h  ","PWWWWWW","John Doe"

But as dates contain the comma character, it was a little bit hard to extract start/end values via the command line.

After removing the toLocaleString() call in schedule:render I was able to do this.

for row in `pd schedule:render -i P999999 --since=2022-01-23T10:00:00.000Z --until=2022-02-07T08:00:00.000Z --filter "User name=Doe" --output=csv --no-header`
do
start=$(echo $row | cut -f1 -d,)
end=$(echo $row | cut -f2 -d,)
pd schedule:override:add -i P999999 -u PUUUUUU --start=$start --end=$end
done

Maybe there is a better way to extract the value in bash. But I suppose you can also provide an option to avoid date formatting.

What do you think?

Regards, Sébastien

martindstone commented 2 years ago

Hi @sdenef-adeo ,

So it's valid CSV that is being output but I know from direct personal experience that that is hard to deal with in bash, lol. With any of the other commands you would have been able to skip the date formatting by specifying the column manually with -k, but apparently i had not put that flag in the schedule:render command. I just published v0.0.83 which adds that flag to the command, so for example:

default date output:

% pd schedule:render -i PXV1QP4 --since '7 days ago' --until 'now' --output=csv 
Getting schedule PXV1QP4... done
Start,End,Duration,User id,User name
"1/12/2022, 1:59:02 PM","1/12/2022, 5:00:00 PM","3 hours","PSD4GQ9","Inara Serra"
"1/12/2022, 5:00:00 PM","1/13/2022, 1:00:00 AM","8 hours","PP2XEKB","River Tam"
"1/13/2022, 1:00:00 AM","1/13/2022, 9:00:00 AM","8 hours","P2VEST2","Zoe Washburne"

specifying -k start and -k end to avoid formatting

% pd schedule:render -i PXV1QP4 --since '7 days ago' --until 'now' -k start -k end --output=csv 
Getting schedule PXV1QP4... done
start,end,Duration,User id,User name
2022-01-12T13:58:55-05:00,2022-01-12T17:00:00-05:00,3 hours,PSD4GQ9,Inara Serra
2022-01-12T17:00:00-05:00,2022-01-13T01:00:00-05:00,8 hours,PP2XEKB,River Tam
2022-01-13T01:00:00-05:00,2022-01-13T09:00:00-05:00,8 hours,P2VEST2,Zoe Washburne

If this looks ok to you, can you update to v0.0.83 and let me know if it resolves your issue?

Thanks! Martin

sdenef-adeo commented 2 years ago

Hi Martin,

Yes, it works well. Thanks.

I close the issue.