How to capture UTC instead of local time in VS Code timestamp snippet? - visual-studio-code

So I've now got this great timestamp inside a code snippet in VS Code.
Full snippet:
"Frontmatter":{
"prefix": "sqFront",
"body": [
"---",
"title: $1",
"permalink: $2",
"description: $3",
"date: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}Z",
"tags:",
"- $0",
"---"
]
}
How do I set the snippet to capture UTC time instead of my local time?

You can use the HyperSnips extension:
Define the following snippet in the language.hsnips file or in all.hsnips file if you want to have it many file types
snippet sqFront "Frontmatter" b
---
title: $1
permalink: $2
description: $3
date: `` d = new Date();
twodigit = n => n.toString().padStart(2,'0');
rv = `${d.getUTCFullYear()}-${twodigit(d.getUTCMonth()+1)}-${twodigit(d.getUTCDate())}T${twodigit(d.getUTCHours())}:${twodigit(d.getUTCMinutes())}:${twodigit(d.getUTCSeconds())}Z` ``
tags:
- $0
---
endsnippet

Related

Exract a id from git show using power shell

I have the below input from a GIT show:
commit d5089c3135e104c2b508fe58d98596c96b2ae19a Merge: bd82ec4 d36607b Author: Thomas <thomas#gmail> Date: Fri Feb 7 18:48:38 2020 +0000 Merged in test_cicd (pull request #93) PIS-504 id="VN.P.1.0.1"
I need to parse the id and then save to the variable .
EX : VN.P.1.0.1
Mycode is
$build = git show
$id = if ($build -match '\bid=("\d"+)\b') { $Matches[1] }
but not working..help anyone?
After you find the idenclosed in double-quotes, get everything not a double quote:
$id = if ($build -match '\bid="([^"]+)"') { $Matches[1] }
# this ^^^^^
Update: based on comments, guessing the actual git output is different than what's displayed in the OP's example. Replaced with \s whitespace character word boundary metacharacter.

Creating multi-line email body in powershell

I keep getting error when I am trying to implement multiple line email body. I am suspecting bad syntax. Can't find any example online. Any suggestions?
Error: Unexpected token 'EmployeeName"] to $AccountExpire"' in expression or statement.
$subject = "Email for $item["EmployeeName"]. Date expire $AccountExpire"
$body=#"
Name: $item["Employee"]
Class: Contractor
Depart: $item["Depart"]
Region: $item["Region"]
Manager: $item["Manager"]
New Date: $NewDate
"#
SendUpdateEmail($subject,$Body)
You need to escape those array index operations with a subexpression ($()):
$subject = "Email for $($item["EmployeeName"]). Date expire $AccountExpire"
Same goes for multi-line strings (or here-strings as they're formally called):
$body=#"
Name: $($item["Employee"])
Class: Contractor
# and so on...
"#
Personally, I'd go for a multi-line template and use the -f format operator to fill in the values:
$bodyTemplate=#'
Name: {0}
Class: Contractor
Depart: {1}
Region: {2}
Manager: {3}
New Date: {4}
'#
$body = $bodyTemplate -f $item["Employee"],$item["Depart"],$item["Region"],$item["Manager"],$NewDate
When using -f, you can also format different types of data, so if $NewDate is a [DateTime] object, you could control formatting for that inside the template, eg.:
#'
Date: {0:HH:mm:ss}
'# -f (Get-Date)
which would produce:
Date: 14:55:09
(assuming you did this a five to 3 in the afternoon)

Markdown, Knitr, Pandoc Header block disappears from output when styles sheet is added

---
title: "![logo](../Shared/logo.jpg) Title Text"
author: "Author Name"
output: html_document
css: styles.css
---
This header information gets output with render or knit2html, but when the css: styles.css and associated code
options(rstudio.markdownToHTML =
function(inputFile, outputFile) {
require(markdown)
markdownToHTML(inputFile, outputFile, stylesheet='custom.css')
}
)
is added to the start up file, the rendered output file has no header output. The first line in the file is the first line after the last "---" in the *.Rmd file. By the way, "Knit HTML" on the individual *.Rmd content works as expected.
Thanks,
Alan
The option rstudio.markdownToHTML is for R Markdown v1 only. The version based on Pandoc is v2, in which case the css field must be put under the html_document field:
---
title: "![logo](../Shared/logo.jpg) Title Text"
author: "Author Name"
output:
html_document:
css: styles.css
---
Please read the documentation.

UTC_TIMESTAMP() to user defined timezone?

I am storing timestamps in my db using UTC_TIMESTAMP().
I want to output them based on user selected timezone. I tried writing a small function to do this, however, it does not output correctly.
// Date/time converter
function convertTZ($date, $tz, $tzFormat)
{
$date = new DateTime($date);
$date->setTimezone(new DateTimeZone($tz));
return $date->format($tzFormat);
}
echo $_SESSION['dtCurrLogin'].'<br />';
echo convertTZ($_SESSION['dtCurrLogin'], 'UTC', 'F j, Y # g:i:s a e');
dtCurrLogin from db = 2013-09-12 01:23:45
the above outputs :
2013-09-12 01:23:45
September 12, 2013 # 5:23:45 am UTC
Obviously this is not correct as I went from UTC to UTC so they should be equal. If I change to output EST then it shows 1:23:45 am, but of course that would not be right either.
Didn't realize I needed to specify incoming timezone... using the following worked for me...
function convertTZ($date_time, $from_tz, $to_tz, $format_tz)
{
$time_object = new DateTime($date_time, new DateTimeZone($from_tz));
$time_object->setTimezone(new DateTimeZone($to_tz));
return $time_object->format($format_tz);
}

Current date / time to RFC 2822 date function with vb / classic asp

I am trying to write a script to push data out to an amazon s3 bucket and I need to generate what I believe is an RFC 2822 date to send in the header request.
The date looks like this "Tue, 12 June 2012 23:41:58 +0000"
I just need a function to generate the correct time format as I am getting the following error.
RequestTimeTooSkewed The difference between the request time and the current time is too large.
This is what I have so far...
<%
sTimeStamp = "Tue, 12 June 2012 23:41:58 +00002012-06-12T22:45:47Z"
sAWSAccessKeyId = "AESDQWDQWD"
sSignature=Encrypt("SecretQWEQWEQWEQWEYAYAY")
AWSServiceUrl = "https://s3.amazonaws.com/"
Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXMLHTTP.open "GET", AWSServiceUrl, False
oXMLHTTP.setRequestHeader "Authorization", "AWS " & sAWSAccessKeyId & ":" & sSignature
oXMLHTTP.setRequestHeader "x-amz-date", sTimeStamp
on error resume next
oXMLHTTP.send sRequest
Response.Write oXMLHTTP.responseText
%>
Any ideas?
The simplest way to do it is to get JScript to help:
<script runat="server" language="javascript">
function JSNow() { return new Date(); }
</script>
Now you can get the string format for the time required with:
Dim sTimeStamp: sTimeStamp = JSNow().toString()