# What's up with Time.local?

**URL:** <https://www.ruby-forum.com/t/whats-up-with-time-local/84251>\
**Category:** Ruby\
**Created:** [February 2, 2007, 6:58pm UTC](https://www.ruby-forum.com/t/whats-up-with-time-local/84251 "2007-02-02T18:58:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [February 2, 2007, 6:58pm UTC](https://www.ruby-forum.com/t/whats-up-with-time-local/84251/1 "2007-02-02T18:58:56Z")

</div>

I need to check some file dates against the budgetary periods of our  
company, to determine where those files get placed. I’m playing with the  
Time.local object. I’ve proven that I can denote which budget period I’m  
in by using the .between? method. But, I get this weird “octal digit”  
error with some of my date entries.

irb(main):001:0\> t = Time.local(2007,09,09,00,00)  
SyntaxError: compile error  
(irb):1: Illegal octal digit  
t = Time.local(2007,09,09,00,00)  
^  
(irb):1: Illegal octal digit  
t = Time.local(2007,09,09,00,00)  
^

I don’t get the error when I specify the following date. It doesn’t seem  
to like the month of September. (-;

irb(main):005:0\> t = Time.local(2007,01,01,00,00)  
=\> Mon Jan 01 00:00:00 -0500 2007

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [February 2, 2007, 7:22pm UTC](https://www.ruby-forum.com/t/whats-up-with-time-local/84251/2 "2007-02-02T19:22:06Z")

</div>

On Feb 2, 2007, at 09:58, Peter B. wrote:

> (irb):1: Illegal octal digit  
> t = Time.local(2007,09,09,00,00)  
> ^  
> (irb):1: Illegal octal digit  
> t = Time.local(2007,09,09,00,00)  
> ^
> 
> I don’t get the error when I specify the following date. It doesn’t  
> seem  
> to like the month of September. (-;

If you put a 0 in front of a number you are specifying an octal  
number instead of a decimal number. Octal is base 8, so there is no  
such thing as an octal number including a digit greater than 7:

t = Time.local 2007, 011, 011, 00, 00

Instead just use base 10:

Time.local 2007, 9, 9, 0, 0

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [February 2, 2007, 7:24pm UTC](https://www.ruby-forum.com/t/whats-up-with-time-local/84251/3 "2007-02-02T19:24:07Z")

</div>

On Feb 2, 2007, at 12:58 PM, Peter B. wrote:

> (irb):1: Illegal octal digit  
> irb(main):005:0\> t = Time.local(2007,01,01,00,00)  
> =\> Mon Jan 01 00:00:00 -0500 2007

In Ruby starting an integer with a leading zero designates that it is  
in octal notation. The non-negative octal integers start 00, 01, …,  
07, 010, 011, … There is no 09.

Bottom line: drop the leading zeros.

Regards, Morton

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [February 2, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/whats-up-with-time-local/84251/4 "2007-02-02T19:25:08Z")

</div>

On Sat, Feb 03, 2007 at 02:58:59AM +0900, Peter B. wrote:

> I need to check some file dates against the budgetary periods of our  
> company, to determine where those files get placed. I’m playing with the  
> Time.local object. I’ve proven that I can denote which budget period I’m  
> in by using the .between? method. But, I get this weird “octal digit”  
> error with some of my date entries.
> 
> irb(main):001:0\> t = Time.local(2007,09,09,00,00)  
> SyntaxError: compile error  
> (irb):1: Illegal octal digit  
> t = Time.local(2007,09,09,00,00)

Numeric literals starting with `0' are interpreted as octal numbers. Try dropping the leading`0’'s.

> ```
> ^
> 
> ```
> 
> (irb):1: Illegal octal digit  
> t = Time.local(2007,09,09,00,00)  
> ^
> 
> I don’t get the error when I specify the following date. It doesn’t seem  
> to like the month of September. (-;
> 
> irb(main):005:0\> t = Time.local(2007,01,01,00,00)  
> =\> Mon Jan 01 00:00:00 -0500 2007

That’s because there is no `9' in the base-8 number system, just like there is no`A’ in the regular base-10 number system (but there is in the base-16  
system a.k.a. hexadecimal).

Hth,

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [February 2, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/whats-up-with-time-local/84251/5 "2007-02-02T19:27:08Z")

</div>

On Feb 2, 6:58 pm, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> ^
> 
> ```
> 
> (irb):1: Illegal octal digit  
> t = Time.local(2007,09,09,00,00)  
> ^

The problem is the leading zero. Time.local(2007, 9, 9, 0, 0) works  
fine.

Number literals with a zero at the beginning are interpreted as octal  
numbers. Since octal numbers only use digits 0…7, 9 is rejected (as  
would be 8).

HTH,  
AdSR

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [February 2, 2007, 8:46pm UTC](https://www.ruby-forum.com/t/whats-up-with-time-local/84251/6 "2007-02-02T20:46:53Z")

</div>

AdSR wrote:

> On Feb 2, 6:58 pm, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ```
> > ^
> > 
> > ```
> > 
> > (irb):1: Illegal octal digit  
> > t = Time.local(2007,09,09,00,00)  
> > ^
> 
> The problem is the leading zero. Time.local(2007, 9, 9, 0, 0) works  
> fine.
> 
> Number literals with a zero at the beginning are interpreted as octal  
> numbers. Since octal numbers only use digits 0…7, 9 is rejected (as  
> would be 8).
> 
> HTH,  
> AdSR

You’re all brilliant. Thanks. Yes, when I re-looked into my book that  
was guiding me with this, I see that all of their sample don’t have a  
leading zero.

-Peter
