Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using ShareLaTeX, which, for those who don't know, is a website that compiles LaTeX on a server. The issue is that when I type \today, it gives my the date of the server. So, for example, right now it is 10:00 PM EST on October 8 and it gives me October 9, 2013. Is there any way I can force EST? preferably for the entire document.

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

For me, EST (UTC−05) and EDT (UTC−06) is nearly always six hours behind my timezone.

Using the datetime package which provides a few counts for formatting and printing timestamps, we can simply test if the current hour (the server’s) is lower than 6 and if subtract 1 from the day. Of course, you will also need to test whether it is currently the first day of the month and need to consider leap years.

Of course, you can always just set a specific \today:

\def\today{It's always today.}

The datetime package offers much more options to format dates and such.

Code

\documentclass{article}
\usepackage{datetime}
\pagestyle{empty}
\begin{document}
\currenttime, \today

\ifnum\currenthour<6 
  \advance\currenthour+18
  \ifnum\day=1
    \testifleapyear\year
    \ifnum\month=1 \month13\advance\year-1\fi
    \advance\month-1
    \day\ifcase\month\or31\or\ifDTleapyear 29\else 28\fi\or31\or30\or31\or30\or31\or
                                                           31\or30\or31\or30\or31\fi
  \else\advance\day-1\fi
\else\advance\currenthour-6\fi

\currenttime, \today
\end{document}

Output

04:52, Wednesday 9th October, 2013
22:52, Tuesday 8th October, 2013

share|improve this answer
add comment

You can do a bit of monkeying about with the definition of \today. Here's the start of something:

It let's you just set the time difference in hour between EST and the remote server's time. (This will not work properly for Feb 28, 29 or March 1 in a leap year!)

This works by looking at \time and computing the difference between LaTeX's internal \time value (in minutes from midnight) and your local time (EST). Based upon that difference you either need to advance a day, stay on the same day, or go back a day. This may have to trigger other changes such as the month and or year.

\documentclass{article}
\makeatletter
%% save time/day/month
\def\ae@test@time{0}

%% personalized version of `\today`
\def\mytoday{%%
  \ifnum\ae@test@time<0\relax
     %% Go Back a day:     
     \ae@set@day@back
  \else
    \ifnum\ae@test@time>1440\relax
      %% Go Forward a day: 
      \ae@set@day@forward
    \else
    %% It's just today:
    \fi
  \fi
  \today
  }

%% Code to set the day back by one                                      
%% If it's the first of the month, then you need to also                
%% set the month back a day.  If it's January and the first of the month
%% you'll need to set the year back.                                    
\def\ae@set@day@back{%%
  \ifnum
    \number\numexpr\day\relax=1\relax
    \ifnum
      \number\numexpr\month\relax=1\relax
      \month=12\relax
      \advance\year-1\relax
    \else
      \advance\month-1\relax
    \fi
    \ifcase\number\numexpr\month\relax
      %% no month "0"
      \or
      \day=31\relax\or%%<-- Jan   
      \day=28\relax\or%%<-- Feb   
      \day=31\relax\or%%<-- March 
      \day=30\relax\or%%<-- April 
      \day=31\relax\or%%<-- May   
      \day=30\relax\or%%<-- Jun   
      \day=31\relax\or%%<-- July  
      \day=31\relax\or%%<-- Aug   
      \day=30\relax\or%%<-- Sept  
      \day=31\relax\or%%<-- Oct   
      \day=30\relax\or%%<-- Nov   
      \day=31\relax%%%%%<-- Dec   
    \fi
  \else
    \advance\day-1\relax
  \fi}

%% Code to set the day forward by one                               
%% You need to test whether it is the last day of the month.        
%% If it's the last day of the month, you need to advance the month.
%% If it's December and the last day of the month, you need to      
%% advance the year.                                                
\def\ae@set@day@forward{%%
  \ifcase\number\numexpr\month\relax
  \or
    \edef\test@day{31}\or%%<-- Jan                    
    \edef\test@day{28}\or%%<-- Feb                    
    \edef\test@day{31}\or%%<-- March                  
    \edef\test@day{30}\or%%<-- April                  
    \edef\test@day{31}\or%%<-- May                    
    \edef\test@day{30}\or%%<-- Jun                    
    \edef\test@day{31}\or%%<-- July                   
    \edef\test@day{31}\or%%<-- Aug                    
    \edef\test@day{30}\or%%<-- Sept                   
    \edef\test@day{31}\or%%<-- Oct                    
    \edef\test@day{30}\or%%<-- Nov                    
    \edef\test@day{31}%%%%%<-- Dec                    
  \fi
  \advance\day+1\relax
  \ifnum\number\numexpr\day\relax>\test@day\relax
    \day=1\relax
    \ifnum\number\numexpr\month=12\relax
      \month=1\relax
      \advance\year+1\relax
    \else
      \advance\month+1\relax
    \fi
  \fi
}

%% Code for setting up the hour difference between EST and the time the remote
%% computer is using.  Set this by "hours".                                   
\def\time@difference{0}
\def\settimedifference#1{\edef\time@difference{\number\numexpr60*#1\relax}%%
                      \edef\ae@test@time{\number\numexpr\time+\time@difference\relax}}
\makeatother
\begin{document}
%% Just testing at various month/year boundaries:
\day=1\relax
\month=10\relax
%% setting up the time difference
%%\settimedifference{-21}
\settimedifference{-21}

Getting today:  \mytoday

\end{document}

This works rather crudely. It currently doesn't get leap years correct. But it should show you something about what you can do.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.