I want Gnuplot to use the norwegian name of the days (%a) as xtics. In Linux I can be done by usingset locale 'nb_NO.utf-8'.
But in Windows 10, when tryingset locale 'Norwegian Bokmål_Norway.1252', this results in the errorLocale not available.
The output of show locale is:
gnuplot LC_CTYPE Norwegian Bokmål_Norway.1252
gnuplot encoding utf8
gnuplot LC_TIME Norwegian Bokmål_Norway.1252
gnuplot LC_NUMERIC C
I suppose the error is due to the character å (unocode 00E5, Latin Small Letter A with ring). How can I set correct locale in Gnuplot when using Windows?
That's what I get with the following code. Tested with gnuplot 5.4 under Win10. I hope it will solve your problem.
Script: (works for gnuplot>=5.0.0 and if you change (i+4) to (i+2) for gnuplot4.6.x)
### set locale to different languages, print weekdays
reset session
myLocales = "English French German Norwegian Icelandic"
do for [myLocale in myLocales] {
set locale myLocale
print sprintf("\n### %s:",myLocale)
do for [i=0:6] { print strftime("%A",3600*24*(i+4)) }
}
### end of script
Result:
### English:
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
### French:
lundi
mardi
mercredi
jeudi
vendredi
samedi
dimanche
### German:
Montag
Dienstag
Mittwoch
Donnerstag
Freitag
Samstag
Sonntag
### Norwegian:
mandag
tirsdag
onsdag
torsdag
fredag
lørdag
søndag
### Icelandic:
mánudagur
þriðjudagur
miðvikudagur
fimmtudagur
föstudagur
laugardagur
sunnudagur
Related
How can I print a stargazer table when summary=F and a character column has elements containing &? summary=F prints the data table verbatim which is what I want.
Here's a case where it prints as expected:
> stargazer::stargazer(
+ data.frame(ur1=c('hot','tamale'),yum='!')
+ ,type='text',summary=F)
============
ur1 yum
------------
1 hot !
2 tamale !
------------
And here the & is split into two columns.
> stargazer::stargazer(
+ data.frame(ur1=c('hot & tamale'),yum='!')
+ ,type='text',summary=F)
============
ur1 yum
------------
1 hot tamale
------------
The same behavior happens in html and latex modes as well. In latex it's easy to hack a fix for a character by commenting out the & a la gsub(x,pattern='&',replacement='\\&',fixed=T) but that fix doesn't work for html and replacing it with the entity & still causes the split. While it would be easy to use kable or simple markdown to print the table, I want my this kind of table to have the same style as the stargazer regression tables.
I hope someone can help! Also, I couldn't find a development repo to report it if it's a bug.
I do have the latest version of stargazer:
> devtools::session_info()
Session info ------------------
setting value
version R version 3.4.4 (2018-03-15)
system x86_64, linux-gnu
ui RStudio (1.1.419)
language (EN)
collate en_US.UTF-8
tz Etc/UTC
date 2018-09-14
Packages ----------------------
stargazer 5.2.2 2018-05-30 CRAN (R 3.4.4)
It's a very hacky solution, but you could insert a tab (\t) and a backspace (\b) escape sequence right before the &. This seems to work for type = "text" and type = "html", but not type = "latex".
dat <- data.frame(ur1=c('hot & tamale', 'hot & taco') ,yum='!')
dat[, 1] <- gsub("&", "\t\b&", dat[, 1])
stargazer::stargazer(dat, type = "text", summary=F)
====================
ur1 yum
--------------------
1 hot & tamale !
2 hot & taco !
--------------------
I'm using PostgresSQL 10 and RPostgreSQL package in R.
I create a new table:
CREATE TABLE people (
id integer NOT NULL,
name character varying,
birthdate date,
deathdate date
);
Then attempt to copy the file :
COPY people (id, name, birthdate, deathdate)
FROM '\people.sql'
ENCODING 'UTF-8';
Then get the following error:
Error in postgresqlExecStatement(conn, statement, ...) : RS-DBI
driver: (could not Retrieve the result : ERROR: invalid input syntax
for integer: "1" CONTEXT: COPY people, line 1, column id: "1"
I did wonder if this was an encoding error, so ran and got:
readr::guess_encoding("\people.sql")
# A tibble: 4 x 2
encoding confidence
<chr> <dbl>
1 UTF-8 1.00
2 windows-1252 0.37
3 windows-1254 0.37
4 windows-1250 0.28
I've tried the other, less probable windows encodings, but this do not work either and throws similar issues with line 1, for instance windows-1252 shows ERROR: invalid input syntax for integer: "1"
The first few lines of the file are:
1 50 Cent 1975-07-06 \N
2 A. Michael Baldwin 1963-04-04 \N
and the last two lines :
8396 Zubaida Sahar \N \N
8397 Zuhair Haddad \N \N
\.
Any idea what could be causing this?
Thank you
Thanks to wildplasser in the comments for this one:
1 - Remove the Byte Order Mark - I used Notepad++ and convert to UTF-8 (see this post)
2 - Completely removed the erroneous end of file marker which was
\.
I am trying to find the date that was seven days before today.
CURRENT_DT=`date +"%F %T"`
diff=$CURRENT_DT-7
echo $diff
I am trying stuff like the above to find the 7 days less than from current date. Could anyone help me out please?
GNU date will to the math for you:
date --date "7 days ago"
Other version will require you to covert the current date into seconds since the UNIX epoch first, manually subtract 7 days' worth of seconds, and convert that back into the desired form. Consult the documentation for your version of date for details on how to convert to and from Unix timestamps. Here's an example using GNU date again:
x=$(date +%s)
x=$((x - 7 * 24 * 60 * 60))
date --date #$x
Here is a simple Perl script which (unlike the other examples) works with Unix:
perl -e 'use POSIX qw(ctime); printf "%s", ctime(time - (7 * 24 * 60 * 60));'
(Tested with Solaris 10, and a token Linux system, of course - with the caveat that Perl is not necessarily part of one's configuration, merely very likely).
Adding this one for shells on OSX:
date -v-7d
> Tue Apr 3 15:16:31 EDT 2018
date
> Tue Apr 10 15:16:33 EDT 2018
Need that formated?
date -v-7d +%Y-%m-%d
> 2018-04-03
Ksh's printf can do time calculation:
$ printf '%(%Y-%m-%d)T\n'
2015-04-07
$ printf '%(%Y-%m-%d)T\n' '7 days ago'
2015-03-31
$
I haven't used unix in a while but I found this in one of my scripts
echo `date +%s`-604800 | bc
DATE=$(date --date "7 days ago" | awk '{print$1,$2,$3}')
echo "$DATE"
if [ -z "$(grep -i "$DATE" test.log)" ]; then
exit 1
fi
sed -i "1,/$DATE/d" test.log
We have a recently internationalised application written in classic ASP. The following code replicates the issue. The value of that field in the recordset is "8.90" and is typed as varchar(255).
session.LCID = 2057
nNumber = recMessages.fields(lCounter)
Response.Write nNumber '' # prints 8.90
Response.Write FormatNumber(8.90) '' # prints 8.90
Response.Write FormatNumber(nNumber) '' # prints 8.90
session.LCID = 1034
nNumber = recMessages.fields(lCounter)
Response.Write nNumber '' # prints 8.90
Response.Write FormatNumber(8.90) '' # prints 8,90
Response.Write FormatNumber(nNumber) '' # prints 890,00!
What is going on here? Why for certain locales would it multiply the number by 1000?
From what you've provided it looks as if the . in 8.90 is being treated as the thousand separator. Is LCID 1034 Spanish?
I'm not sure but I think if you check the number formatting for that locale it will use period as the separator.
Cheers
On different locales, different characters are used as decimal and thousand separators. While dot (.) is a decimal separator on the 2057 locale, it's most likely used as a thousand separator on the 1034 locale.
To workaround the issue, you could try replacing the dot character in the field value with the locale-specific decimal separator. I'm not sure, but something like this should work:
session.LCID = 1034
strDecSep = Mid(CStr(CDbl(3/2)), 2, 1)
nNumber = recMessages.fields(lCounter)
nNumber = Replace(nNumber, ".", strDecSep)
It's not that it multiplies by 1000. The number is being formatted to that country's currency format.
For instance in the US, 1234.56 would be formatted as $1,234.56, in Spain same number would be 1.234,56
I have a tab delimited file where each record has a timestamp field in 12-hour format:
mm/dd/yyyy hh:mm:ss [AM|PM].
I need to quickly convert these fields to 24-hour time:
mm/dd/yyyy HH:mm:ss.
What would be the best way to do this? I'm running on a Windows platform, but I have access to sed, awk, perl, python, and tcl in addition to the usual Windows tools.
Using Perl and hand-crafted regexes instead of facilities like strptime:
#!/bin/perl -w
while (<>)
{
# for date times that don't use leading zeroes, use this regex instead:
# (?:\d{1,2}/\d{1,2}/\d{4} )(\d{1,2})(?::\d\d:\d\d) (AM|PM)
while (m%(?:\d\d/\d\d/\d{4} )(\d\d)(?::\d\d:\d\d) (AM|PM)%)
{
my $hh = $1;
$hh -= 12 if ($2 eq 'AM' && $hh == 12);
$hh += 12 if ($2 eq 'PM' && $hh != 12);
$hh = sprintf "%02d", $hh;
# for date times that don't use leading zeroes, use this regex instead:
# (\d{1,2}/\d{1,2}/\d{4} )(\d{1,2})(:\d\d:\d\d) (?:AM|PM)
s%(\d\d/\d\d/\d{4} )(\d\d)(:\d\d:\d\d) (?:AM|PM)%$1$hh$3%;
}
print;
}
That's very fussy - but also converts possibly multiple timestamps per line.
Note that the transformation for AM/PM to 24-hour is not trivial.
12:01 AM --> 00:01
12:01 PM --> 12:01
01:30 AM --> 01:30
01:30 PM --> 13:30
Now tested:
perl ampm-24hr.pl <<!
12/24/2005 12:01:00 AM
09/22/1999 12:00:00 PM
12/12/2005 01:15:00 PM
01/01/2009 01:56:45 AM
12/30/2009 10:00:00 PM
12/30/2009 10:00:00 AM
!
12/24/2005 00:01:00
09/22/1999 12:00:00
12/12/2005 13:15:00
01/01/2009 01:56:45
12/30/2009 22:00:00
12/30/2009 10:00:00
Added:
In What is a Simple Way to Convert Between an AM/PM Time and 24 hour Time in JavaScript, an alternative algorithm is provided for the conversion:
$hh = ($1 % 12) + (($2 eq 'AM') ? 0 : 12);
Just one test...probably neater.
It is a 1-line thing in python:
time.strftime('%H:%M:%S', time.strptime(x, '%I:%M %p'))
Example:
>>> time.strftime('%H:%M:%S', time.strptime('08:01 AM', '%I:%M %p'))
'08:01:00'
>>> time.strftime('%H:%M:%S', time.strptime('12:01 AM', '%I:%M %p'))
'00:01:00'
Use Pythons datetime module someway like this:
import datetime
infile = open('input.txt')
outfile = open('output.txt', 'w')
for line in infile.readlines():
d = datetime.strptime(line, "input format string")
outfile.write(d.strftime("output format string")
Untested code with no error checking. Also it reads the entire input file in memory before starting.
(I know there is plenty of room for improvements like with statement...I make this a community wiki entry if anyone likes to add something)
To just convert the hour field, in python:
def to12(hour24):
return (hour24 % 12) if (hour24 % 12) > 0 else 12
def IsPM(hour24):
return hour24 > 11
def to24(hour12, isPm):
return (hour12 % 12) + (12 if isPm else 0)
def IsPmString(pm):
return "PM" if pm else "AM"
def TestTo12():
for x in range(24):
print x, to12(x), IsPmString(IsPM(x))
def TestTo24():
for pm in [False, True]:
print 12, IsPmString(pm), to24(12, pm)
for x in range(1, 12):
print x, IsPmString(pm), to24(x, pm)
This might be too simple thinking, but why not import it into excel, select the entire column and change the date format, then re-export as a tab delimited file? (I didn't test this, but it somehow sounds logical to me :)
Here i have converted 24 Hour system to 12 Hour system.
Try to use this method for your problem.
DateFormat fmt = new SimpleDateFormat("yyyyMMddHHssmm");
try {
Date date =fmt.parse("20090310232344");
System.out.println(date.toString());
fmt = new SimpleDateFormat("dd-MMMM-yyyy hh:mm:ss a ");
String dateInString = fmt.format(date);
System.out.println(dateInString);
} catch (Exception e) {
System.out.println(e.getMessage());
}
RESULT:
Tue Mar 10 23:44:23 IST 2009
10-March-2009 11:44:23 PM
In Python: Converting 12hr time to 24hr time
import re
time1=input().strip().split(':')
m=re.search('(..)(..)',time1[2])
sec=m.group(1)
tz=m.group(2)
if(tz='PM'):
time[0]=int(time1[0])+12
if(time1[0]=24):
time1[0]-=12
time[2]=sec
else:
if(int(time1[0])=12):
time1[0]-=12
time[2]=sec
print(time1[0]+':'+time1[1]+':'+time1[2])
Since you have multiple languages, I'll suggest the following algorithm.
1 Check the timestamp for the existence of the "PM" string.
2a If PM does not exist, simply convert the timestamp to the datetime object and proceed.
2b If PM does exist, convert the timestamp to the datetime object, add 12 hours, and proceed.