wtime

Submitted scripts and programs
Forum rules
Your own work only.
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

wtime

Unread post by machinebacon » Sat Jun 28, 2014 5:45 pm

Shows the time and date in other time zones. Taken from http://stackoverflow.com/questions/3700 ... orld-clock and modified to make it work in Debian

Code: Select all

#!/bin/sh
search=$1
zoneinfo=/usr/share/zoneinfo/posix/*/*
format='%a %F %T'
find $zoneinfo \
    | grep -i "$search" \
    | while read z
      do
          d=$(TZ=$z date +"$format")
          printf "%-34s %23s\n" ${z#$zoneinfo} "$d"
      done
Usage:

Code: Select all

wtime Berlin
wtime new YorK
wtime Australia
..gnutella..

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: wtime

Unread post by wuxmedia » Sat Jun 28, 2014 5:52 pm

cool, handy - seeing as I think every one of us is in a differnet zone 8)
"Seek, and Ye shall find"
"Github | Chooons | Site"

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: wtime

Unread post by pidsley » Sat Jun 28, 2014 10:30 pm

Nice script! I had an idea for a modification -- if people post their timezones, I could modify the script to tell us what time it is for each user -- "wtime wuxmedia" would tell us what time it is in wux land. If there is any interest, please post your timezone, or what you use for /etc/localtime. I use "America/Los_Angeles"

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: wtime

Unread post by dkeg » Sat Jun 28, 2014 10:50 pm

Yes, good idea.

America/New_York

Work hard; Complain less

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: wtime

Unread post by machinebacon » Sun Jun 29, 2014 6:29 am

Great idea, Asia/Shanghai


Edit:

Code: Select all

bbq@grill:~$ cat /etc/localtime 
CST-8
..gnutella..

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: wtime

Unread post by wuxmedia » Sun Jun 29, 2014 7:28 am

I'm in my own zone, man 8)
nah:

Europe/London
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
paolo
Head Banger
Posts: 275
Joined: Mon Nov 12, 2012 11:08 am
Location: Milano,Italy

Re: wtime

Unread post by paolo » Sun Jun 29, 2014 8:49 am

Great !
For me Europe/Rome
Dell Latitude C640 - CPU P4 2GHz - RAM 1,5 GB - made in 2002 - I'm in the Manjaro-i3 land now :)

User avatar
kexolino
Common Boob
Posts: 557
Joined: Sun Jun 16, 2013 1:57 pm

Re: wtime

Unread post by kexolino » Sun Jun 29, 2014 9:00 am

Good stuff. Europe/Belgrade here.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: wtime

Unread post by GekkoP » Sun Jun 29, 2014 9:08 am

Europe/Rome here.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: wtime

Unread post by dkeg » Sun Jun 29, 2014 2:37 pm

don't mean to derail, but cat /etc/localtime just spit out a bunch of nonesense.

My time is set, but I also ran, with no change

Code: Select all

/usr/bin/tzselect
and

Code: Select all

dpkg-reconfigure tzdata

Work hard; Complain less

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: wtime

Unread post by bones » Sun Jun 29, 2014 2:47 pm

America/Los_Angeles

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: wtime

Unread post by machinebacon » Sun Jun 29, 2014 3:00 pm

@drew, check the second line in your /etc/localtime, that's the right format :)
..gnutella..

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: wtime

Unread post by pidsley » Sun Jun 29, 2014 3:24 pm

Sorry dkeg. Try "cat /etc/timezone" on Debian.

User avatar
wei2912
runs Stable
Posts: 36
Joined: Wed Jun 18, 2014 7:59 pm
Location: Singapore

Re: wtime

Unread post by wei2912 » Sun Jun 29, 2014 3:39 pm

We could have a bot in the channel for that? :D

Asia/Singapore, GMT +8
GitHub || Blog

"Don't blindly believe what I say. Don't believe me because others convince you of my words. Don't believe anything you see, read, or hear from others, whether of authority, religious teachers or texts." - Buddha

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: wtime

Unread post by pidsley » Sun Jun 29, 2014 4:12 pm

Ok, here's what I have so far. Here is the list:

Code: Select all

pidsley America/Los_Angeles
bones America/Los_Angeles
dkeg America/New_York
machinebacon Asia/Shanghai
wuxmedia Europe/London
paolo Europe/Rome
kexolino Europe/Belgrade
GekkoP Europe/Rome
wei2912 Asia/Singapore
rhowaldt Europe/Amsterdam
Alad Europe/Brussels
zazen23 America/Chicago
kiiroitori Asia/Tokyo
Note that user names cannot contain spaces. If more people provide information, simply add them to the list.

And here is the script.

Code: Select all

#!/bin/bash

# script to print the current time for a list of users
# call with no arguments to print the entire list
# call with username to print for just that user
# username is not case sensitive, and you may specify only the first few letters
# for example "utime wux" will show you the current time for wuxmedia

ZONELIST=~/.config/utime/ulist # change this if you put the list somewhere else

print-time() {
    [[ $1 = "" ]] && exit
    echo "$1  $(TZ=$2 date)  $2"
}

shopt -s nocasematch    # make string compares not case sensitive
while read line; do
    if [[ $1 = "" ]]; then # no user name specified, print all
        print-time $line
    elif [[ $line =~ ^$1 ]]; then # user name specified and found
        print-time $line
        exit
    fi
done < $ZONELIST

[[ $1 != "" ]] && echo "could not find user $1"

Code: Select all

$ utime kex
kexolino   Sun Jun 29 17:15:10 CEST 2014   Europe/Belgrade

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: wtime

Unread post by wuxmedia » Sun Jun 29, 2014 4:44 pm

nice array :)
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: wtime

Unread post by dkeg » Sun Jun 29, 2014 7:18 pm

pidsley, thanks, nice work on the expansion of the script. Should be helpful before heading into IRC.

Edit: Some cleanup. /etc/timezone worked fine. and rho, I add you to my list!

Work hard; Complain less

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: wtime

Unread post by rhowaldt » Sun Jun 29, 2014 7:35 pm

fwiw: europe/amsterdam here
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: wtime

Unread post by pidsley » Sun Jun 29, 2014 7:53 pm

^ thanks. Added to the list.

User avatar
Alad
should take a shower
Posts: 447
Joined: Wed May 21, 2014 12:52 am

Re: wtime

Unread post by Alad » Sun Jun 29, 2014 9:02 pm

Europe/Brussels.
It's funny how we used to be able to do real stuff with rudimentary computers, but now we can't. -- ratcheer

Post Reply