When I pass a date mm-dd-yyyy in a variable in strptime in rubymine feature, it throws error.
query = 04-11-1998
Then(/^I see (.*) on the form$/) do |query|
mdate1 = Date.strptime(query,"%m-%d-%Y")
puts "parsing output1 is #{mdate1}"
mdate2 = DateTime.parse(mdate1).strftime("%a %b %d %Y 00:00:00 GMT+0000")
Argument Error: invalid date in strptime.
If run the separate ruby file just mdate1 = Date.strptime(query,"%m-%d-%Y") and print it, it working fine
Pls let know how to resolve.
This isn't a cucumber issue it's a ruby / coding issue.
It's likely that because you're using different object classes that's where your conflict is coming from.
Related
Currently I am working on a bash script which has hardcoded the following date:
2022-12-08T15:25:30.165965Z
I would like to generate that date in the script and I would like it to be up to date. What I have tried so far is:
date '+%d-%m-%Y %H:%M:%S.%M'
which outputs:
19-12-2022 12:40:13.40
I was wondering if someone knows how I could add the T and Z letters in the time?
You may use:
date -u '+%d-%m-%YT%H:%M:%S.%NZ'
Here:
-u will print UTC date-time
T before %H will print literal T
%N prints nanosecond value
Z after %N will print literal Z
$ date -u '+%FT%T.%6NZ'
2022-12-19T15:04:34.238733Z
You need GNU date for nanoseconds though.
With just bash using the EPOCHREALTIME variable and printf's %(fmt)T directive.
( IFS=.; TZ=UTC printf '%(%FT%T)T.%sZ\n' $EPOCHREALTIME )
# => 2022-12-19T14:28:33.343999Z
I'm using a subshell so that changing IFS does not affect the rest of the script.
I am utilizing subprocess in order to grab the hexdump for a .tgz file as I require the hex string. The only problem is, hexdump is throwing a bad format error, but only when the command is issues through subprocess. I believe I have escaped everything correctly, but I can't figure out why I am not getting my intended output:
def package_plugin():
plugin_hex = subprocess.run(["hexdump", "-v", "-e", "'1/1 \"\\\\x%%02x\"'", "package.tgz"])
This results in an error: hexdump: "'1/1 "''x%%02x"'": bad format. However, if I just run the command straight in the terminal I receive the expected output of a hexstring with the '\x' separating the hex.
How should I be running this to store the output in a Python variable? Is my command being mangled somehow and hence not executing correctly? Any advice is appreciated.
Thanks
EDIT: I should add that when entering in the terminal the command is hexdump -v -e '1/1 "\\x%02x"' I am not sure why the extra '%' sign is shown in the error as it should be interpreting as a single % sign.
Nevermind. I couldn't figure this out but I solved it with hexlify:
def package_plugin():
plugin_hex = ""
with open('plugin.tgz', 'rb') as f:
for chunk in iter(lambda: f.read(32), b''):
plugin_hex += binascii.hexlify(chunk).decode("utf-8")
formatted_hex = '\\x' + '\\x'.join(plugin_hex[i:i+2] for i in range(0, len(plugin_hex), 2))
i have shell script to set date and time automatically, on boot up after connecting to internet, my script is as follows
RESULT="wget -qO- http://xx5.xx2.xx6.x1:7019/api/values/getcurrenttime"
echo Current Time $RESULT
TimeSetRet="$(date --set=$RESULT)"
echo ret: $TimeSetRet
output of above script as follow
Current Time "23 MAR 2017 15:27:58"
date: extra operand ‘2017’
Why is that error i am getting?
format is correct and if i try to do manually in command line i get result but in shell it is giving error,
please help me with this issue.
you probably need to have " or \" at the right place... it probably splits up the text as different arguments at the moment
There are few scripts getting called in my main script, one of which when executed separately executes well, but when executed from the main, gives an error as below,
((: s<=: syntax error: operand expected (error token is "=")
s is my variable in my for loop as,
for((s=1;s<=$someVar;s++))
I'm exporting this someVar from my main script, so that this script can use that var, however its already able to get the value of that var.
someVar is not set with a value.
I'm able to reproduce it with this:
for((s=1;s<=$someVar;s++)); do
:
done
Error output:
... 3: ((: s<=: syntax error: operand expected (error token is "=")
P.S. You're probably running Bash 3.x.
i'm trying to get an old date in a bash script, but it throws this error
"./bkc.sh: line 10: 20130122: command not found"
It's like tries to use the result date as a function instead of assign the value to the OLDATE var.
Here's my code:
OLDATE= `date -d '7 days ago' +'%Y%m%d'`
Can anyone help me ? Thanks
Just remove the space between OLDATE and the command.
Bash doesn't want spaces in assigning values