~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to test/misc/make_date_test.py

  • Committer: William Grant
  • Date: 2009-12-08 10:05:52 UTC
  • Revision ID: grantw@unimelb.edu.au-20091208100552-51qd6m3pl3h2owkk
Improve the diff/log breadcrumbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# Run in a user's jail to test the "short date format" displayed in the
 
3
# file browser's file table.
 
4
#
 
5
# Generates a bunch of files in the current directory and sets their date
 
6
# stamps to various dates in the past.
 
7
# The files are named after their date stamps relative to today.
 
8
#
 
9
# Author: Matt Giuca
 
10
# Date: 13/1/2008
 
11
 
 
12
import os
 
13
import time
 
14
 
 
15
seconds_per_day = 60*60*24
 
16
time_now = time.time()
 
17
 
 
18
if time.daylight:
 
19
    timezone_offset = time.altzone
 
20
else:
 
21
    timezone_offset = time.timezone
 
22
 
 
23
# Time at the beginning of today, local time
 
24
local_daystart \
 
25
    = time_now - int(time_now - timezone_offset) % seconds_per_day
 
26
 
 
27
def make_file_days_ago(days_ago):
 
28
    global time_now
 
29
    make_file(str(days_ago) + "days",
 
30
        time_now - seconds_per_day*days_ago)
 
31
def make_file(fname, timestamp):
 
32
    f = open(fname, 'w')
 
33
    f.close()
 
34
    os.utime(fname, (timestamp, timestamp))
 
35
 
 
36
make_file_days_ago(0)
 
37
make_file_days_ago(1)
 
38
make_file_days_ago(2)
 
39
make_file_days_ago(3)
 
40
make_file_days_ago(4)
 
41
make_file_days_ago(5)
 
42
make_file_days_ago(6)
 
43
make_file_days_ago(7)
 
44
make_file_days_ago(10)
 
45
make_file_days_ago(365)
 
46
 
 
47
# Now a boundary test - Make a file in the last second of Yesterday.
 
48
make_file("first_second_today", local_daystart)
 
49
make_file("last_second_yesterday", local_daystart-1)