| |
| /pliant/language/data/id.pli |
| |
| 1 |
# Copyright Hubert Tonneau hubert.tonneau@pliant.cx | |
| 2 |
# | |
| 3 |
# This program is free software; you can redistribute it and/or | |
| 4 |
# modify it under the terms of the GNU General Public License version 2 | |
| 5 |
# as published by the Free Software Foundation. | |
| 6 |
# | |
| 7 |
# This program is distributed in the hope that it will be useful, | |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 |
# GNU General Public License for more details. | |
| 11 |
# | |
| 12 |
# You should have received a copy of the GNU General Public License | |
| 13 |
# version 2 along with this program; if not, write to the Free Software | |
| 14 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 15 |
| |
| 16 |
module "/pliant/install/ring2.pli" | |
| 17 |
| |
| 18 |
gvar Str header | |
| 19 |
gvar Float start | |
| 20 |
gvar Float stop | |
| 21 |
gvar Sem sem | |
| 22 |
gvar Str previous | |
| 23 |
gvar Int counter | |
| 24 |
| |
| 25 |
function setup_year | |
| 26 |
datetime split (var Int year) (var Int month) (var Int day) (var Int hour) (var Int minute) (var Int second) (var Float fraction) | |
| 27 |
header := right (string year-2000 "radix 36") 2 "0" | |
| 28 |
start := (datetime year 1 1 0 0 0 0.0):seconds | |
| 29 |
stop := (datetime year+1 1 1 0 0 0 0.0):seconds | |
| 30 |
setup_year | |
| 31 |
| |
| 32 |
| |
| 33 |
function generate_id -> id | |
| 34 |
arg Str id | |
| 35 |
var DateTime now := datetime | |
| 36 |
sem request | |
| 37 |
if now:seconds>=stop | |
| 38 |
setup_year | |
| 39 |
var Int second := cast datetime:seconds-start Int | |
| 40 |
id := header+(right (string second "radix 36") 5 "0") | |
| 41 |
if id<>previous | |
| 42 |
previous := id | |
| 43 |
counter := 0 | |
| 44 |
if counter>0 | |
| 45 |
var Str extra := string counter "radix 36" | |
| 46 |
id += (string extra:len)+extra | |
| 47 |
counter += 1 | |
| 48 |
sem release | |
| 49 |
| |
| 50 |
export generate_id | |
| |