A "Today" function or script?

How could Trunk be improved?

A "Today" function or script?

Postby fogleman » Sun Jul 18, 2010 2:27 pm

I create journal entry for each day using the timestamp function. Is there a way to create a link on my home page that will always take me to the current day's journal entry. If I can't do this with a script, can you add it as a function?

Jay
fogleman
 
Posts: 55
Joined: Sun Jun 13, 2010 1:53 pm

Re: A "Today" function or script?

Postby moioci » Sun Jul 18, 2010 4:19 pm

It seems like it ought to work to add an entry to your home page like [[{{timestamp MM_dd_yyyy}}]], but apparently functions are not evaluated inside of [[]].
moioci
 
Posts: 110
Joined: Mon Jun 07, 2010 1:37 pm
Location: Birmingham, AL, USA

Re: A "Today" function or script?

Postby fogleman » Wed Sep 29, 2010 8:55 am

Bump. Since this is not yet a function, can anyone suggest a bit of javacript that would work? Each day, I begin a page named 2010-09-29 etc. I woul like be able to access "today's page" using a link or button.
fogleman
 
Posts: 55
Joined: Sun Jun 13, 2010 1:53 pm

Re: A "Today" function or script?

Postby froggyntoady » Thu Sep 30, 2010 12:54 am

This is a bit cumbersome, but you could give "Today's" page a special tag "Today", and use the {{tagged Today}} function to display a link to just today's note. But then each day you'd have to tag the new day's note with Today, and change yesterday's note's tag from Today to eg, Past, with which you could use to display links to all past notes with {{tagged Past}}

Lou
froggyntoady
 
Posts: 58
Joined: Sun Apr 18, 2010 7:23 am

Re: A "Today" function or script?

Postby Xar » Thu Sep 30, 2010 8:11 am

@fogleman

try this:

Code: Select all
### Today: <span id=today>today</span>

<script>
datum= new(Date); // get today's date 
sep="-";  // define separator 
dy=datum.getDate(); // get day of the month 
if (dy<10) dy="0"+ dy; // add leading zero when necessary
mo=datum.getMonth() + 1; // get month
if (mo<10) mo="0" + mo; // add zero  
yr=datum.getFullYear();  // get year
      //   now put everything together, adding  "tn://" in front to make it a Wikilink
res= "tn://" + yr + sep + mo + sep + dy ;
today.innerHTML=res; // and put it inside the <span> with the id=today
</script>


Hope it will work for you

Cheers

Franz
Xar
 
Posts: 22
Joined: Tue Sep 28, 2010 7:41 am
Location: Munich Germany

Re: A "Today" function or script?

Postby fogleman » Thu Sep 30, 2010 6:07 pm

This is awesome! Right now when I insert your script, I see a link:

Today: tn://2010-09-30

where the tn://2010-09-30 is a link that takes me to today's page. Is there a way to display the link as "Today" instead of tn://2010-09-30 ?? If not, that's okay. I am happy to have the dynamic link!

Thanks again!

Jay
fogleman
 
Posts: 55
Joined: Sun Jun 13, 2010 1:53 pm

Re: A "Today" function or script?

Postby Xar » Thu Sep 30, 2010 7:37 pm

just insert the following line before the last line of the script:

Code: Select all
res= "<a href="+res+">Today</a>";


Instead of the word "Today" you could use any other text you want to be displayed as a link.
Xar
 
Posts: 22
Joined: Tue Sep 28, 2010 7:41 am
Location: Munich Germany

Re: A "Today" function or script?

Postby fogleman » Fri Oct 01, 2010 12:56 am

This is perfect. Thanks for going to this trouble!

I inserted your script on my "TopMenu" page so the Today link appears on every page where I insert this topmenu.
fogleman
 
Posts: 55
Joined: Sun Jun 13, 2010 1:53 pm

Re: A "Today" function or script?

Postby mgkennard » Fri Oct 01, 2010 9:53 pm

@Xar great use of JavaScript to enhance Trunk Notes. I've just linked to this post on the appsonthemove Twitter

Matthew
Apps On The Move
mgkennard
Site Admin
 
Posts: 758
Joined: Mon Jul 21, 2008 2:40 pm

Re: A "Today" function or script?

Postby fogleman » Wed Oct 06, 2010 11:33 am

Thanks again to Xar for solving my need for a "Today" link in my TopMenu. I added a few lines to the script so that I can also have a "Yesterday" and "Tomorrow" buttons. LOL I can never leave well enough alone. So I have a question.

I'd like to use this script to define a snippet that will write the current date. I was hopeful when I created the snippet page and the script seemed to produce the date. Here is the scrpt:
Code: Select all
<span id=today>today</span>

<script>
datum= new(Date); // get today's date 
sep="-";  // define separator 
dy=datum.getDate(); // get day of the month 
dy2= parseInt(dy,10) + parseInt(1,10);
dy3= parseInt(dy,10) + parseInt(-1,10);
if (dy<10) dy="0"+ dy; // add leading zero when necessary
if (dy2<10) dy2="0"+ dy2; // add leading zero when necessary
if (dy3<10) dy3="0"+ dy3; // add leading zero when necessary
mo=datum.getMonth() + 1; // get month
if (mo<10) mo="0" + mo; // add zero  
yr=datum.getFullYear();  // get year
      //   now put everything together, adding  "tn://" in front to make it a Wikilink
res= yr + sep + mo + sep + dy ;
res2="tn://" + yr + sep + mo + sep + dy2;
res3="tn://" + yr + sep + mo + sep + dy3;
res2= "<a href="+res2+">Tomorrow</a";
res3= "<a href="+res3+">Yesterday</a";
today.innerHTML=res; // and put it inside the <span> with the id=today;
tomorrow.innerHTML=res2;
yesterday.innerHTML=res3;
</script>



The problem is that when I use the snippet, the variable name S"today" is not replaced by the date. Any Ideas on how to make this work?

- Jay
Last edited by fogleman on Wed Oct 06, 2010 11:21 pm, edited 1 time in total.
fogleman
 
Posts: 55
Joined: Sun Jun 13, 2010 1:53 pm

Next

Return to Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests

cron